Skip to content

Commit

Permalink
Allow launching restore through a dialer code
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chirayudesai committed Sep 29, 2021
1 parent a5a3a85 commit 38f0176
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/stevesoltys/seedvault/SecretCodeReceiver.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 38f0176

Please sign in to comment.