Use secure settings for backup enable / transport selection
This commit is contained in:
@@ -33,6 +33,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@@ -42,7 +43,6 @@ import android.os.Message;
|
|||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemProperties;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
@@ -74,9 +74,9 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
private static final String TAG = "BackupManagerService";
|
private static final String TAG = "BackupManagerService";
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
|
|
||||||
// Persistent properties
|
// Secure settings
|
||||||
private static final String BACKUP_TRANSPORT_PROPERTY = "persist.service.bkup.trans";
|
private static final String BACKUP_TRANSPORT_SETTING = "backup_transport";
|
||||||
private static final String BACKUP_ENABLED_PROPERTY = "persist.service.bkup.enabled";
|
private static final String BACKUP_ENABLED_SETTING = "backup_enabled";
|
||||||
|
|
||||||
// Default time to wait after data changes before we back up the data
|
// Default time to wait after data changes before we back up the data
|
||||||
private static final long COLLECTION_INTERVAL = 3 * 60 * 1000;
|
private static final long COLLECTION_INTERVAL = 3 * 60 * 1000;
|
||||||
@@ -166,7 +166,8 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
// Set up our bookkeeping
|
// Set up our bookkeeping
|
||||||
// !!! STOPSHIP: make this disabled by default so that we then gate on
|
// !!! STOPSHIP: make this disabled by default so that we then gate on
|
||||||
// setupwizard or other opt-out UI
|
// setupwizard or other opt-out UI
|
||||||
mEnabled = SystemProperties.getBoolean(BACKUP_ENABLED_PROPERTY, true);
|
mEnabled = (Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
BACKUP_ENABLED_SETTING, 1) != 0);
|
||||||
mBaseStateDir = new File(Environment.getDataDirectory(), "backup");
|
mBaseStateDir = new File(Environment.getDataDirectory(), "backup");
|
||||||
mDataDir = Environment.getDownloadCacheDirectory();
|
mDataDir = Environment.getDownloadCacheDirectory();
|
||||||
|
|
||||||
@@ -191,8 +192,13 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
|
|
||||||
mGoogleTransport = null;
|
mGoogleTransport = null;
|
||||||
// !!! TODO: set up the default transport name "the right way"
|
// !!! TODO: set up the default transport name "the right way"
|
||||||
mCurrentTransport = SystemProperties.get(BACKUP_TRANSPORT_PROPERTY,
|
mCurrentTransport = Settings.Secure.getString(mContext.getContentResolver(),
|
||||||
"com.google.android.backup/.BackupTransportService");
|
BACKUP_TRANSPORT_SETTING);
|
||||||
|
if (mCurrentTransport == null) {
|
||||||
|
mCurrentTransport = "com.google.android.backup/.BackupTransportService";
|
||||||
|
Settings.Secure.putString(mContext.getContentResolver(),
|
||||||
|
BACKUP_TRANSPORT_SETTING, mCurrentTransport);
|
||||||
|
}
|
||||||
if (DEBUG) Log.v(TAG, "Starting with transport " + mCurrentTransport);
|
if (DEBUG) Log.v(TAG, "Starting with transport " + mCurrentTransport);
|
||||||
|
|
||||||
// Attach to the Google backup transport. When this comes up, it will set
|
// Attach to the Google backup transport. When this comes up, it will set
|
||||||
@@ -1148,7 +1154,8 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
|
|
||||||
boolean wasEnabled = mEnabled;
|
boolean wasEnabled = mEnabled;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
SystemProperties.set(BACKUP_ENABLED_PROPERTY, enable ? "true" : "false");
|
Settings.Secure.putInt(mContext.getContentResolver(), BACKUP_ENABLED_SETTING,
|
||||||
|
enable ? 1 : 0);
|
||||||
mEnabled = enable;
|
mEnabled = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1206,7 +1213,8 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
if (mTransports.get(transport) != null) {
|
if (mTransports.get(transport) != null) {
|
||||||
prevTransport = mCurrentTransport;
|
prevTransport = mCurrentTransport;
|
||||||
mCurrentTransport = transport;
|
mCurrentTransport = transport;
|
||||||
SystemProperties.set(BACKUP_TRANSPORT_PROPERTY, transport);
|
Settings.Secure.putString(mContext.getContentResolver(), BACKUP_TRANSPORT_SETTING,
|
||||||
|
transport);
|
||||||
Log.v(TAG, "selectBackupTransport() set " + mCurrentTransport
|
Log.v(TAG, "selectBackupTransport() set " + mCurrentTransport
|
||||||
+ " returning " + prevTransport);
|
+ " returning " + prevTransport);
|
||||||
} else {
|
} else {
|
||||||
@@ -1334,13 +1342,14 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
synchronized (mQueueLock) {
|
synchronized (mQueueLock) {
|
||||||
|
pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled"));
|
||||||
pw.println("Available transports:");
|
pw.println("Available transports:");
|
||||||
for (String t : listAllTransports()) {
|
for (String t : listAllTransports()) {
|
||||||
String pad = (t.equals(mCurrentTransport)) ? " * " : " ";
|
String pad = (t.equals(mCurrentTransport)) ? " * " : " ";
|
||||||
pw.println(pad + t);
|
pw.println(pad + t);
|
||||||
}
|
}
|
||||||
int N = mBackupParticipants.size();
|
int N = mBackupParticipants.size();
|
||||||
pw.println("Participants:");
|
pw.println("Participants: " + N);
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
int uid = mBackupParticipants.keyAt(i);
|
int uid = mBackupParticipants.keyAt(i);
|
||||||
pw.print(" uid: ");
|
pw.print(" uid: ");
|
||||||
|
|||||||
Reference in New Issue
Block a user