Fix problem where rotating the device doesn't launch TrustAgent pref
This fixes a bug where the TrustAgent intent was being lost when the device configurtion changes. It used to depend on a view that gets recreated. Instead, we persist the actual launch intent which works across activity restarts. Fixes bug 17040470 Change-Id: Ia1c93867254cfdc27683a767cf41fe74dbb97db0
This commit is contained in:
@@ -63,6 +63,7 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
|||||||
*/
|
*/
|
||||||
public class SecuritySettings extends SettingsPreferenceFragment
|
public class SecuritySettings extends SettingsPreferenceFragment
|
||||||
implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
|
implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
|
||||||
|
private static final String TRUST_AGENT_CLICK_INTENT = "trust_agent_click_intent";
|
||||||
static final String TAG = "SecuritySettings";
|
static final String TAG = "SecuritySettings";
|
||||||
private static final Intent TRUST_AGENT_INTENT =
|
private static final Intent TRUST_AGENT_INTENT =
|
||||||
new Intent(TrustAgentService.SERVICE_INTERFACE);
|
new Intent(TrustAgentService.SERVICE_INTERFACE);
|
||||||
@@ -127,7 +128,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private boolean mIsPrimary;
|
private boolean mIsPrimary;
|
||||||
|
|
||||||
private Preference mClickedTrustAgentPreference;
|
private Intent mTrustAgentClickIntent;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -138,6 +139,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
|
||||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
||||||
|
|
||||||
|
if (savedInstanceState != null
|
||||||
|
&& savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
|
||||||
|
mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getResIdForLockUnlockScreen(Context context,
|
private static int getResIdForLockUnlockScreen(Context context,
|
||||||
@@ -504,6 +510,14 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
mLockAfter.setEnabled(revisedEntries.size() > 0);
|
mLockAfter.setEnabled(revisedEntries.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
if (mTrustAgentClickIntent != null) {
|
||||||
|
outState.putParcelable(TRUST_AGENT_CLICK_INTENT, mTrustAgentClickIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -554,12 +568,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
} else if (KEY_TRUST_AGENT.equals(key)) {
|
} else if (KEY_TRUST_AGENT.equals(key)) {
|
||||||
ChooseLockSettingsHelper helper =
|
ChooseLockSettingsHelper helper =
|
||||||
new ChooseLockSettingsHelper(this.getActivity(), this);
|
new ChooseLockSettingsHelper(this.getActivity(), this);
|
||||||
mClickedTrustAgentPreference = preference;
|
mTrustAgentClickIntent = preference.getIntent();
|
||||||
if (!helper.launchConfirmationActivity(CHANGE_TRUST_AGENT_SETTINGS, null, null) &&
|
if (!helper.launchConfirmationActivity(CHANGE_TRUST_AGENT_SETTINGS, null, null) &&
|
||||||
preference.getIntent() != null) {
|
mTrustAgentClickIntent != null) {
|
||||||
// If this returns false, it means no password confirmation is required.
|
// If this returns false, it means no password confirmation is required.
|
||||||
startActivity(preference.getIntent());
|
startActivity(mTrustAgentClickIntent);
|
||||||
mClickedTrustAgentPreference = null;
|
mTrustAgentClickIntent = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we didn't handle it, let preferences handle it.
|
// If we didn't handle it, let preferences handle it.
|
||||||
@@ -587,13 +601,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
// because mBiometricWeakLiveliness could be null
|
// because mBiometricWeakLiveliness could be null
|
||||||
return;
|
return;
|
||||||
} else if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
|
} else if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
|
||||||
if (mClickedTrustAgentPreference != null) {
|
if (mTrustAgentClickIntent != null) {
|
||||||
Intent intent = mClickedTrustAgentPreference.getIntent();
|
startActivity(mTrustAgentClickIntent);
|
||||||
if (intent != null) {
|
mTrustAgentClickIntent = null;
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
mClickedTrustAgentPreference = null;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user