Remove READ_PHONE_STATE permission
This commit is contained in:
parent
9cede639f3
commit
7455f4afb9
5 changed files with 1 additions and 60 deletions
10
Android.mk
10
Android.mk
|
@ -1,13 +1,5 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := default-permissions_com.stevesoltys.backup.xml
|
||||
LOCAL_MODULE_CLASS := ETC
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/default-permissions
|
||||
LOCAL_SRC_FILES := $(LOCAL_MODULE)
|
||||
include $(BUILD_PREBUILT)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := permissions_com.stevesoltys.backup.xml
|
||||
LOCAL_MODULE_CLASS := ETC
|
||||
|
@ -38,4 +30,4 @@ LOCAL_MODULE_CLASS := APPS
|
|||
LOCAL_PRIVILEGED_MODULE := true
|
||||
LOCAL_DEX_PREOPT := false
|
||||
LOCAL_REQUIRED_MODULES := permissions_com.stevesoltys.backup.xml whitelist_com.stevesoltys.backup.xml
|
||||
include $(BUILD_PREBUILT)
|
||||
include $(BUILD_PREBUILT)
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
android:name="android.permission.BACKUP"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<!-- This is needed to retrieve the serial number of the device,
|
||||
so we can store the backups for each device in a unique location -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<application
|
||||
android:name=".Backup"
|
||||
android:allowBackup="false"
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
package com.stevesoltys.backup
|
||||
|
||||
import android.Manifest.permission.READ_PHONE_STATE
|
||||
import android.app.Application
|
||||
import android.app.backup.IBackupManager
|
||||
import android.content.Context.BACKUP_SERVICE
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.ServiceManager.getService
|
||||
import android.util.Log
|
||||
import com.stevesoltys.backup.crypto.KeyManager
|
||||
import com.stevesoltys.backup.crypto.KeyManagerImpl
|
||||
import com.stevesoltys.backup.settings.getDeviceName
|
||||
import com.stevesoltys.backup.settings.setDeviceName
|
||||
import io.github.novacrypto.hashing.Sha256.sha256Twice
|
||||
|
||||
private const val URI_AUTHORITY_EXTERNAL_STORAGE = "com.android.externalstorage.documents"
|
||||
|
||||
private val TAG = Backup::class.java.simpleName
|
||||
|
||||
/**
|
||||
* @author Steve Soltys
|
||||
* @author Torsten Grote
|
||||
|
@ -38,27 +30,6 @@ class Backup : Application() {
|
|||
BackupNotificationManager(this)
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
storeDeviceName()
|
||||
}
|
||||
|
||||
private fun storeDeviceName() {
|
||||
if (getDeviceName(this) != null) return // we already have a stored device name
|
||||
|
||||
val permission = READ_PHONE_STATE
|
||||
if (checkSelfPermission(permission) != PERMISSION_GRANTED) {
|
||||
throw AssertionError("You need to grant the $permission permission.")
|
||||
}
|
||||
// TODO consider just using a hash for the entire device name and store metadata in an encrypted file
|
||||
val id = sha256Twice(Build.getSerial().toByteArray(Utf8))
|
||||
.copyOfRange(0, 8)
|
||||
.encodeBase64()
|
||||
val name = "${Build.MANUFACTURER} ${Build.MODEL} ($id)"
|
||||
Log.i(TAG, "Initialized device name to: $name")
|
||||
setDeviceName(this, name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun Uri.isOnExternalStorage() = authority == URI_AUTHORITY_EXTERNAL_STORAGE
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.*
|
|||
|
||||
private const val PREF_KEY_BACKUP_URI = "backupUri"
|
||||
private const val PREF_KEY_BACKUP_TOKEN = "backupToken"
|
||||
private const val PREF_KEY_DEVICE_NAME = "deviceName"
|
||||
private const val PREF_KEY_BACKUP_PASSWORD = "backupLegacyPassword"
|
||||
|
||||
fun setBackupFolderUri(context: Context, uri: Uri) {
|
||||
|
@ -41,17 +40,6 @@ fun getBackupToken(context: Context): Long {
|
|||
return getDefaultSharedPreferences(context).getLong(PREF_KEY_BACKUP_TOKEN, 0L)
|
||||
}
|
||||
|
||||
fun setDeviceName(context: Context, name: String) {
|
||||
getDefaultSharedPreferences(context)
|
||||
.edit()
|
||||
.putString(PREF_KEY_DEVICE_NAME, name)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun getDeviceName(context: Context): String? {
|
||||
return getDefaultSharedPreferences(context).getString(PREF_KEY_DEVICE_NAME, null)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced by KeyManager#getBackupKey()")
|
||||
fun getBackupPassword(context: Context): String? {
|
||||
return getDefaultSharedPreferences(context).getString(PREF_KEY_BACKUP_PASSWORD, null)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<exceptions>
|
||||
<exception package="com.stevesoltys.backup">
|
||||
<permission name="android.permission.READ_PHONE_STATE" fixed="true"/>
|
||||
</exception>
|
||||
</exceptions>
|
Loading…
Reference in a new issue