AR/FR: Settings changes.
The basic AOSP settings infrastrucutre. Will add the Google specific resources and tests to GoogleSettings in the next AR/FR change. Test: make DEBUG_ROBOLECTRIC=1 RunSettingsRoboTests -j40 ROBOTEST_FILTER=com.android.settings.MasterClearTest.java Change-Id: I7278b5c6d2a72e71d81c7fa5f937a2313d6c322c
This commit is contained in:
@@ -9198,4 +9198,11 @@
|
|||||||
<!-- Keywords for Storage Access settings -->
|
<!-- Keywords for Storage Access settings -->
|
||||||
<string name="keywords_storage_access">storage access scoped directory</string>
|
<string name="keywords_storage_access">storage access scoped directory</string>
|
||||||
|
|
||||||
|
<!-- Account type associated with the backup account. Empty for AOSP. [DO NOT TRANSLATE] -->
|
||||||
|
<string name="account_type"></string>
|
||||||
|
<!-- Package to target for Account credential confirmation. This will allow users to
|
||||||
|
remind/rediscover their backup account password prior to a reset. Empty for AOSP.
|
||||||
|
[DO NOT TRANSLATE] -->
|
||||||
|
<string name="account_confirmation_package"></string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -28,6 +28,7 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -39,6 +40,7 @@ import android.os.UserManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.telephony.euicc.EuiccManager;
|
import android.telephony.euicc.EuiccManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -74,6 +76,7 @@ public class MasterClear extends InstrumentedPreferenceFragment {
|
|||||||
private static final String TAG = "MasterClear";
|
private static final String TAG = "MasterClear";
|
||||||
|
|
||||||
private static final int KEYGUARD_REQUEST = 55;
|
private static final int KEYGUARD_REQUEST = 55;
|
||||||
|
private static final int CREDENTIAL_CONFIRM_REQUEST = 56;
|
||||||
|
|
||||||
static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
|
static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
|
||||||
static final String ERASE_ESIMS_EXTRA = "erase_esim";
|
static final String ERASE_ESIMS_EXTRA = "erase_esim";
|
||||||
@@ -114,7 +117,7 @@ public class MasterClear extends InstrumentedPreferenceFragment {
|
|||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
if (requestCode != KEYGUARD_REQUEST) {
|
if (requestCode != KEYGUARD_REQUEST || requestCode != CREDENTIAL_CONFIRM_REQUEST) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,6 +141,33 @@ public class MasterClear extends InstrumentedPreferenceFragment {
|
|||||||
args, R.string.master_clear_confirm_title, null, null, 0);
|
args, R.string.master_clear_confirm_title, null, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean tryShowAccountConfirmation() {
|
||||||
|
final Context context = getActivity();
|
||||||
|
final String accountType = context.getString(R.string.account_type);
|
||||||
|
final String packageName = context.getString(R.string.account_confirmation_package);
|
||||||
|
if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(packageName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final AccountManager am = AccountManager.get(context);
|
||||||
|
Account[] accounts = am.getAccountsByType(accountType);
|
||||||
|
if (accounts != null && accounts.length > 0) {
|
||||||
|
final Intent requestAccountConfirmation = new Intent()
|
||||||
|
.setPackage(packageName)
|
||||||
|
.setAction("android.accounts.action.PRE_FACTORY_RESET");
|
||||||
|
// Check to make sure that the intent is supported.
|
||||||
|
final PackageManager pm = context.getPackageManager();
|
||||||
|
final List<ResolveInfo> resolutions =
|
||||||
|
pm.queryIntentActivities(requestAccountConfirmation, 0);
|
||||||
|
if (resolutions != null && resolutions.size() > 0) {
|
||||||
|
getActivity().startActivityForResult(
|
||||||
|
requestAccountConfirmation, CREDENTIAL_CONFIRM_REQUEST);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the user clicks to begin the reset sequence, we next require a
|
* If the user clicks to begin the reset sequence, we next require a
|
||||||
* keyguard confirmation if the user has currently enabled one. If there
|
* keyguard confirmation if the user has currently enabled one. If there
|
||||||
@@ -158,7 +188,10 @@ public class MasterClear extends InstrumentedPreferenceFragment {
|
|||||||
.setAction(Intent.ACTION_FACTORY_RESET);
|
.setAction(Intent.ACTION_FACTORY_RESET);
|
||||||
context.startActivity(requestFactoryReset);
|
context.startActivity(requestFactoryReset);
|
||||||
}
|
}
|
||||||
} else if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tryShowAccountConfirmation() && !runKeyguardConfirmation(KEYGUARD_REQUEST)) {
|
||||||
showFinalConfirmation();
|
showFinalConfirmation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -160,6 +160,13 @@ public class MasterClearTest {
|
|||||||
assertThat(componentName.getPackageName()).isEqualTo(intent.getPackage());
|
assertThat(componentName.getPackageName()).isEqualTo(intent.getPackage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTryShowAccountConfirmation_unsupported() {
|
||||||
|
doReturn(mActivity).when(mMasterClear).getActivity();
|
||||||
|
/* Using the default resources, account confirmation shouldn't trigger */
|
||||||
|
assertThat(mMasterClear.tryShowAccountConfirmation()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
private void initScrollView(int height, int scrollY, int childBottom) {
|
private void initScrollView(int height, int scrollY, int childBottom) {
|
||||||
when(mScrollView.getHeight()).thenReturn(height);
|
when(mScrollView.getHeight()).thenReturn(height);
|
||||||
when(mScrollView.getScrollY()).thenReturn(scrollY);
|
when(mScrollView.getScrollY()).thenReturn(scrollY);
|
||||||
|
Reference in New Issue
Block a user