Remove backup preferences if backup service is inactive
Also show informative message instead. Bug: 16641441 Change-Id: I9920c07d56c4c0ccb1f3dce637c0fb390902d2ff
This commit is contained in:
@@ -4378,6 +4378,10 @@
|
|||||||
<string name="auto_restore_title">Automatic restore</string>
|
<string name="auto_restore_title">Automatic restore</string>
|
||||||
<!-- Summary text of the "automatic restore" setting -->
|
<!-- Summary text of the "automatic restore" setting -->
|
||||||
<string name="auto_restore_summary">When reinstalling an app, restore backed up settings and data</string>
|
<string name="auto_restore_summary">When reinstalling an app, restore backed up settings and data</string>
|
||||||
|
<!-- Title of the preference informing the user about the backup service being inactive [CHAR LIMIT=50]-->
|
||||||
|
<string name="backup_inactive_title">Backup service is inactive.</string>
|
||||||
|
<!-- Summary text of the preference informing the user about the backup service being inactive, explaining that this is likely set by device policy [CHAR LIMIT=150]-->
|
||||||
|
<string name="backup_inactive_summary">This is set by your device policy.</string>
|
||||||
|
|
||||||
<!-- Local (desktop) backup password menu title [CHAR LIMIT=25] -->
|
<!-- Local (desktop) backup password menu title [CHAR LIMIT=25] -->
|
||||||
<string name="local_backup_password_title">Desktop backup password</string>
|
<string name="local_backup_password_title">Desktop backup password</string>
|
||||||
|
@@ -43,6 +43,14 @@
|
|||||||
android:summary="@string/auto_restore_summary"
|
android:summary="@string/auto_restore_summary"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="backup_inactive"
|
||||||
|
android:title="@string/backup_inactive_title"
|
||||||
|
android:summary="@string/backup_inactive_summary"
|
||||||
|
android:persistent="false"
|
||||||
|
android:enabled="false"
|
||||||
|
android:selectable="false" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:key="personal_data_category"
|
<PreferenceCategory android:key="personal_data_category"
|
||||||
|
@@ -30,11 +30,13 @@ import android.os.ServiceManager;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.SwitchPreference;
|
import android.preference.SwitchPreference;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
@@ -55,7 +57,9 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String BACKUP_DATA = "backup_data";
|
private static final String BACKUP_DATA = "backup_data";
|
||||||
private static final String AUTO_RESTORE = "auto_restore";
|
private static final String AUTO_RESTORE = "auto_restore";
|
||||||
private static final String CONFIGURE_ACCOUNT = "configure_account";
|
private static final String CONFIGURE_ACCOUNT = "configure_account";
|
||||||
|
private static final String BACKUP_INACTIVE = "backup_inactive";
|
||||||
private static final String PERSONAL_DATA_CATEGORY = "personal_data_category";
|
private static final String PERSONAL_DATA_CATEGORY = "personal_data_category";
|
||||||
|
private static final String TAG = "PrivacySettings";
|
||||||
private IBackupManager mBackupManager;
|
private IBackupManager mBackupManager;
|
||||||
private SwitchPreference mBackup;
|
private SwitchPreference mBackup;
|
||||||
private SwitchPreference mAutoRestore;
|
private SwitchPreference mAutoRestore;
|
||||||
@@ -88,15 +92,23 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_ACCOUNT);
|
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_ACCOUNT);
|
||||||
|
|
||||||
if (UserManager.get(getActivity()).hasUserRestriction(
|
ArrayList<String> keysToRemove = getNonVisibleKeys(getActivity());
|
||||||
UserManager.DISALLOW_FACTORY_RESET)) {
|
final int screenPreferenceCount = screen.getPreferenceCount();
|
||||||
screen.removePreference(findPreference(PERSONAL_DATA_CATEGORY));
|
for (int i = screenPreferenceCount - 1; i >= 0; --i) {
|
||||||
|
Preference preference = screen.getPreference(i);
|
||||||
|
if (keysToRemove.contains(preference.getKey())) {
|
||||||
|
screen.removePreference(preference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PreferenceCategory backupCategory = (PreferenceCategory) findPreference(BACKUP_CATEGORY);
|
||||||
|
if (backupCategory != null) {
|
||||||
|
final int backupCategoryPreferenceCount = backupCategory.getPreferenceCount();
|
||||||
|
for (int i = backupCategoryPreferenceCount - 1; i >= 0; --i) {
|
||||||
|
Preference preference = backupCategory.getPreference(i);
|
||||||
|
if (keysToRemove.contains(preference.getKey())) {
|
||||||
|
backupCategory.removePreference(preference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vendor specific
|
|
||||||
if (getActivity().getPackageManager().
|
|
||||||
resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
|
|
||||||
screen.removePreference(findPreference(BACKUP_CATEGORY));
|
|
||||||
}
|
}
|
||||||
updateToggles();
|
updateToggles();
|
||||||
}
|
}
|
||||||
@@ -285,6 +297,40 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
|
return getNonVisibleKeys(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ArrayList<String> getNonVisibleKeys(Context context) {
|
||||||
|
final ArrayList<String> nonVisibleKeys = new ArrayList<String>();
|
||||||
|
final IBackupManager backupManager = IBackupManager.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||||
|
boolean isServiceActive = false;
|
||||||
|
try {
|
||||||
|
isServiceActive = backupManager.isBackupServiceActive(UserHandle.myUserId());
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed querying backup manager service activity status. " +
|
||||||
|
"Assuming it is inactive.");
|
||||||
|
}
|
||||||
|
if (isServiceActive) {
|
||||||
|
nonVisibleKeys.add(BACKUP_INACTIVE);
|
||||||
|
} else {
|
||||||
|
nonVisibleKeys.add(AUTO_RESTORE);
|
||||||
|
nonVisibleKeys.add(CONFIGURE_ACCOUNT);
|
||||||
|
nonVisibleKeys.add(BACKUP_DATA);
|
||||||
|
}
|
||||||
|
if (UserManager.get(context).hasUserRestriction(
|
||||||
|
UserManager.DISALLOW_FACTORY_RESET)) {
|
||||||
|
nonVisibleKeys.add(PERSONAL_DATA_CATEGORY);
|
||||||
|
}
|
||||||
|
// Vendor specific
|
||||||
|
if (context.getPackageManager().
|
||||||
|
resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
|
||||||
|
nonVisibleKeys.add(BACKUP_CATEGORY);
|
||||||
|
}
|
||||||
|
return nonVisibleKeys;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user