Skip to content

Instantly share code, notes, and snippets.

@hadilq
hadilq / guide.md
Last active March 27, 2018 16:01
Encrypting More: /boot Joins The Party

Encrypting More: /boot Joins The Party

The story started by reading this. But in my case this setup didn't work out because of the EFI partition. So here I'm writing to remember what I did.

Andvantages

First of all, the advantages of encrypting /boot partition are

  • As Dusty mentioned there're some dangers to leaving the bootloader and ramdisks unencrypted.
  • Also my original /boot partition had 250MB which was not enough, but now it's not complaining anymore.
class SingleLiveEvent<T> : MutableLiveData<T>() {
private val observers = CopyOnWriteArraySet<ObserverWrapper<T>>()
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
val wrapper = ObserverWrapper(observer)
observers.add(wrapper)
super.observe(owner, wrapper)
}
/**
* A wrapper for database and network states.
*/
sealed class ResultState<T> {
/**
* A state of [data] which shows that we know there is still an update to come.
*/
data class Loading<T>(val data: T) : ResultState<T>()
/**
* The base repository to handle important functionality of repositories.
*
* @param E the entity that is related to this repository. Every repository responsible for
* one and only one entity.
*/
abstract class BaseRepository<E : Entity> {
/**
* Loads an entity from database and network.
class BaseRepositoryTest {
@Test
fun `test loading with success`() {
val persist = { _: EntityTest -> }
val entityTest = EntityTest()
val usecaseFlowable: Flowable<ResultState<EntityTest>> = TestRepository().performTest(
Flowable.just(listOf(entityTest)),
interface Action
abstract class BaseViewModel : ViewModel() {
val actionStream = PublishSubject.create<Action>()
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
protected fun Disposable.track() {
compositeDisposable.add(this)
}
override fun onCleared() {
compositeDisposable.clear()
inline fun <T, reified E : T> Observable<in T>.filterTo(
@Suppress("UNUSED_PARAMETER") target: Class<E>
): Observable<out E> = this.filter {
when (it) {
is E -> true
else -> false
}
}.map { it as E }
class ExampleViewModel @Inject constructor(
...
) : BaseViewModel() {
init {
actionStream.filterTo(ClickedAction::class.java)
.subscribe(::clicked).track()
}
private fun clicked(clickedAction: clickedAction) {
private fun clicked() {
viewModel.actionStream.onNext(ClickedAction())
}