Allow launching restore through a dialer code

* We don't show Restore in menu by default since it's
  not the best idea to restore a running system
* However, at the same time, it's good to have a way to do
  that for those who'd like to restore anyway, and the only
  current way is adb, which is not ideal
* Dialing "*#*#RESTORE#*#*" will launch the restore activity

Change-Id: I258fead82f7e916a4de0b314e1840d7aa4b3746c
This commit is contained in:
Chirayu Desai 2021-07-12 20:57:30 +05:30
parent a5a3a85c6c
commit 38f01765ec
2 changed files with 33 additions and 0 deletions

View file

@ -116,6 +116,15 @@
</intent-filter>
</receiver>
<receiver
android:name=".SecretCodeReceiver">
<intent-filter>
<action android:name="android.telephony.action.SECRET_CODE" />
<!-- *#*#RESTORE#*#* -->
<data android:scheme="android_secret_code" android:host="7378673" />
</intent-filter>
</receiver>
<!-- Used to start actual BackupService depending on scheduling criteria -->
<service
android:name=".storage.StorageBackupJobService"

View file

@ -0,0 +1,24 @@
package com.stevesoltys.seedvault
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.util.Log
import com.stevesoltys.seedvault.restore.RestoreActivity
private val TAG = BroadcastReceiver::class.java.simpleName
private val RESTORE_SECRET_CODE = "7378673"
class SecretCodeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val host = intent.data.host
if (!RESTORE_SECRET_CODE.equals(host)) return
Log.d(TAG, "Restore secret code received.")
val i = Intent(context, RestoreActivity::class.java).apply {
flags = FLAG_ACTIVITY_NEW_TASK
}
context.startActivity(i)
}
}