Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adfec556 authored by Anton Philippov's avatar Anton Philippov
Browse files

Add a screen to show OEM backup settings.

Moves the backup settings logic to BackupSettingsHelper and
BackupSettingsActivity:
- If the manufacturer provides the intent and the label for their backup
settings in the config.xml, a new intermediate fragment is shown for
Backup settings to let the user pick either standard backup settings or
OEM provided backup settings.
- If config.xml doesn't contain the intent, BackupSettingsActivity is
used as a trampoline activity to launch backup settings provided by the
backup transport of the default backup settings activity, i.e.
PrivacySettingsActivity.

Bug: 34700410
Bug: 33655074
Bug: 33654991
Test: make RunSettingsRoboTests
Change-Id: I78e340fbf926b2a9dc2c4e3942f9337c3c7a933c
parent 0c341d73
Loading
Loading
Loading
Loading
+2 −21
Original line number Diff line number Diff line
@@ -1373,11 +1373,6 @@
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.VOICE_LAUNCH" />
            </intent-filter>
            <intent-filter android:priority="-2">
                <action android:name="com.android.settings.action.SETTINGS" />
            </intent-filter>
            <meta-data android:name="com.android.settings.category"
                android:value="com.android.settings.category.personal" />
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.PrivacySettings" />
            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -3007,10 +3002,9 @@
                       android:resource="@string/gesture_preference_summary" />
        </activity>

        <activity android:name="BackupSettingsActivity"
        <activity android:name=".backup.BackupSettingsActivity"
                  android:label="@string/privacy_settings_title"
                  android:icon="@drawable/ic_settings_backup"
                  android:theme="@android:style/Theme.NoDisplay"
                  android:taskAffinity="com.android.settings"
                  android:parentActivityName="Settings">
            <intent-filter android:priority="1">
@@ -3268,21 +3262,8 @@
                       android:value="true" />
        </activity-alias>

        <activity-alias android:name="PrivacyDashboardAlias"
            android:targetActivity="Settings$PrivacySettingsActivity">
            <intent-filter android:priority="60">
                <action android:name="com.android.settings.action.SETTINGS" />
            </intent-filter>
            <meta-data android:name="com.android.settings.category"
                       android:value="com.android.settings.category.ia.system" />
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                       android:value="com.android.settings.PrivacySettings" />
            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                       android:value="true" />
        </activity-alias>

        <activity-alias android:name="BackupResetDashboardAlias"
                        android:targetActivity=".BackupSettingsActivity">
                        android:targetActivity=".backup.BackupSettingsActivity">
            <intent-filter android:priority="60">
                <action android:name="com.android.settings.action.SETTINGS" />
            </intent-filter>
+4 −1
Original line number Diff line number Diff line
@@ -45,9 +45,12 @@
    <string name="config_wallpaper_picker_package" translatable="false">com.android.settings</string>
    <string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>

    <!-- Backup settings to launch -->
    <!-- Manufacturer backup settings to launch -->
    <string name="config_backup_settings_intent" translatable="false"></string>

    <!-- Manufacturer backup settings label -->
    <string name="config_backup_settings_label" translatable="true"></string>

    <!-- Double twist sensor name and vendor used by gesture setting -->
    <string name="gesture_double_twist_sensor_name" translatable="false"></string>
    <string name="gesture_double_twist_sensor_vendor" translatable="false"></string>
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2017 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
    android:title="@string/privacy_settings_title">

    <!-- Backup settings provided by the backup transport or the default settings -->
    <Preference
        android:key="backup_settings" />

    <!-- Backup settings provided by the manufacturer -->
    <Preference
        android:key="manufacturer_backup" />

</PreferenceScreen>
+0 −72
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings;

import android.app.Activity;
import android.app.backup.BackupManager;
import android.app.backup.IBackupManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;

import com.android.settings.R;

import java.net.URISyntaxException;

/**
 * A trampoline activity used to launch the configured Backup activity.
 * This activity used the theme NoDisplay to minimize the flicker that might be seen for the launch-
 * finsih transition.
 */
public class BackupSettingsActivity extends Activity {
    private static final String TAG = "BackupSettingsActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String backup = getResources().getString(R.string.config_backup_settings_intent);
        if (!TextUtils.isEmpty(backup)) {
            try {
                Intent intent = Intent.parseUri(backup, 0);
                if (intent.resolveActivity(getPackageManager()) != null) {
                    // use startActivityForResult to let the activity check the caller signature
                    IBackupManager bmgr = IBackupManager.Stub.asInterface(
                            ServiceManager.getService(Context.BACKUP_SERVICE));
                    boolean backupOkay;
                    try {
                        backupOkay = bmgr.isBackupServiceActive(UserHandle.myUserId());
                    } catch (Exception e) {
                        // things go wrong talking to the backup system => ignore and
                        // pass the default 'false' as the "backup is a thing?" state.
                        backupOkay = false;
                    }
                    intent.putExtra(BackupManager.EXTRA_BACKUP_SERVICES_AVAILABLE, backupOkay);
                    startActivityForResult(intent, -1);
                } else {
                    Log.e(TAG, "Backup component not found!");
                }
            } catch (URISyntaxException e) {
                Log.e(TAG, "Invalid backup component URI!", e);
            }
        }
        finish();
    }
}
 No newline at end of file
+4 −21
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.widget.SearchView;

import com.android.internal.util.ArrayUtils;
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
import com.android.settings.dashboard.DashboardContainerFragment;
@@ -965,29 +966,11 @@ public class SettingsActivity extends SettingsDrawerActivity
            }
        }

        String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
        boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
        // Enable/disable backup settings depending on whether the user is admin.
        setTileEnabled(new ComponentName(packageName,
                Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin);
                BackupSettingsActivity.class.getName()), true, isAdmin);
        setTileEnabled(new ComponentName(packageName,
                        "com.android.settings.PrivacyDashboardAlias"),
                useDefaultBackup, isAdmin);

        boolean hasBackupActivity = false;
        if (!useDefaultBackup) {
            try {
                Intent intent = Intent.parseUri(backupIntent, 0);
                hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
            } catch (URISyntaxException e) {
                Log.e(LOG_TAG, "Invalid backup intent URI!", e);
            }
        }

        // Enable/disable BackupSettingsActivity and its alias.
        setTileEnabled(new ComponentName(packageName,
                BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin);
        setTileEnabled(new ComponentName(packageName,
                "com.android.settings.BackupResetDashboardAlias"), hasBackupActivity, isAdmin);
                "com.android.settings.BackupResetDashboardAlias"), true, isAdmin);

        setTileEnabled(new ComponentName(packageName,
                Settings.EnterprisePrivacySettingsActivity.class.getName()),
Loading