am ef1961c7: am 7cce6d0c: am f330857a: am b852fcbd: Merge "Offer \'ask\' as an available app-linking state" into mnc-dev

* commit 'ef1961c7326aa60e1e3bbb738394c535b7f952af':
  Offer 'ask' as an available app-linking state
This commit is contained in:
Christopher Tate
2015-07-20 18:17:05 +00:00
committed by Android Git Automerger
3 changed files with 73 additions and 42 deletions

View File

@@ -6580,6 +6580,15 @@
<item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps can open their supported links</item> <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps can open their supported links</item>
</plurals> </plurals>
<!-- Explanation that the app that will ALWAYS be launched to open web links to domains that it understands -->
<string name="app_link_open_always">Open in this app</string>
<!-- Explanation that the user will be asked whether to launch the app to open web links to domains that it understands -->
<string name="app_link_open_ask">Ask every time</string>
<!-- Explanation that the app that will NEVER be launched to open web links to domains that it understands -->
<string name="app_link_open_never">Don&#8217;t open in this app</string>
<!-- Fingerprint hint message when finger was not recognized.--> <!-- Fingerprint hint message when finger was not recognized.-->
<string name="fingerprint_not_recognized">Not recognized</string> <string name="fingerprint_not_recognized">Not recognized</string>

View File

@@ -20,18 +20,16 @@
<PreferenceCategory android:key="app_launch_domain_links" <PreferenceCategory android:key="app_launch_domain_links"
android:title="@string/app_launch_domain_links_title"> android:title="@string/app_launch_domain_links_title">
<SwitchPreference <com.android.settings.DropDownPreference
android:key="app_launch_open_domain_urls" android:key="app_link_state"
android:title="@string/app_launch_open_domain_urls_title" android:persistent="false"
android:summary="@string/app_launch_open_domain_urls_summary" android:title="@string/app_launch_open_domain_urls_title" />
/>
<com.android.settings.applications.AppDomainsPreference <com.android.settings.applications.AppDomainsPreference
android:key="app_launch_supported_domain_urls" android:key="app_launch_supported_domain_urls"
android:title="@string/app_launch_supported_domain_urls_title" android:title="@string/app_launch_supported_domain_urls_title"
android:persistent="false" android:persistent="false"
android:dependency="app_launch_open_domain_urls" android:dependency="app_link_state"
/> />
</PreferenceCategory> </PreferenceCategory>

View File

@@ -31,9 +31,13 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.settings.DropDownPreference;
import com.android.settings.DropDownPreference.Callback;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS; import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER; import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
@@ -43,14 +47,14 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
Preference.OnPreferenceChangeListener { Preference.OnPreferenceChangeListener {
private static final String TAG = "AppLaunchSettings"; private static final String TAG = "AppLaunchSettings";
private static final String KEY_OPEN_DOMAIN_URLS = "app_launch_open_domain_urls"; private static final String KEY_APP_LINK_STATE = "app_link_state";
private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls"; private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls";
private static final String KEY_CLEAR_DEFAULTS = "app_launch_clear_defaults"; private static final String KEY_CLEAR_DEFAULTS = "app_launch_clear_defaults";
private PackageManager mPm; private PackageManager mPm;
private boolean mHasDomainUrls; private boolean mHasDomainUrls;
private SwitchPreference mOpenDomainUrls; private DropDownPreference mAppLinkState;
private AppDomainsPreference mAppDomainUrls; private AppDomainsPreference mAppDomainUrls;
private ClearDefaultsPreference mClearDefaultsPreference; private ClearDefaultsPreference mClearDefaultsPreference;
@@ -62,9 +66,6 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
mPm = getActivity().getPackageManager(); mPm = getActivity().getPackageManager();
mOpenDomainUrls = (SwitchPreference) findPreference(KEY_OPEN_DOMAIN_URLS);
mOpenDomainUrls.setOnPreferenceChangeListener(this);
mHasDomainUrls = mHasDomainUrls =
(mAppEntry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0; (mAppEntry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
List<IntentFilterVerificationInfo> iviList = mPm.getIntentFilterVerifications(mPackageName); List<IntentFilterVerificationInfo> iviList = mPm.getIntentFilterVerifications(mPackageName);
@@ -78,20 +79,62 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS); mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS);
updateDomainUrlPrefState(); buildStateDropDown();
} }
private void updateDomainUrlPrefState() { private void buildStateDropDown() {
mOpenDomainUrls.setEnabled(mHasDomainUrls); mAppLinkState = (DropDownPreference) findPreference(KEY_APP_LINK_STATE);
boolean checked = false; // Designed order of states in the dropdown:
//
// * always
// * ask
// * never
mAppLinkState.addItem(R.string.app_link_open_always,
INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS);
mAppLinkState.addItem(R.string.app_link_open_ask,
INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK);
mAppLinkState.addItem(R.string.app_link_open_never,
INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER);
mAppLinkState.setEnabled(mHasDomainUrls);
if (mHasDomainUrls) { if (mHasDomainUrls) {
final int status = mPm.getIntentVerificationStatus(mPackageName, UserHandle.myUserId()); // Present 'undefined' as 'ask' because the OS treats them identically for
if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { // purposes of the UI (and does the right thing around pending domain
checked = true; // verifications that might arrive after the user chooses 'ask' in this UI).
} final int state = mPm.getIntentVerificationStatus(mPackageName, UserHandle.myUserId());
mAppLinkState.setSelectedValue(
(state == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED)
? INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK
: state);
// Set the callback only after setting the initial selected item
mAppLinkState.setCallback(new Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
return updateAppLinkState((Integer) value);
}
});
} }
mOpenDomainUrls.setChecked(checked); }
private boolean updateAppLinkState(final int newState) {
final int userId = UserHandle.myUserId();
final int priorState = mPm.getIntentVerificationStatus(mPackageName, userId);
if (priorState == newState) {
return false;
}
boolean success = mPm.updateIntentVerificationStatus(mPackageName, newState, userId);
if (success) {
// Read back the state to see if the change worked
final int updatedState = mPm.getIntentVerificationStatus(mPackageName, userId);
success = (newState == updatedState);
} else {
Log.e(TAG, "Couldn't update intent verification status!");
}
return success;
} }
private CharSequence[] getEntries(String packageName, List<IntentFilterVerificationInfo> iviList, private CharSequence[] getEntries(String packageName, List<IntentFilterVerificationInfo> iviList,
@@ -104,7 +147,6 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
protected boolean refreshUi() { protected boolean refreshUi() {
mClearDefaultsPreference.setPackageName(mPackageName); mClearDefaultsPreference.setPackageName(mPackageName);
mClearDefaultsPreference.setAppEntry(mAppEntry); mClearDefaultsPreference.setAppEntry(mAppEntry);
updateDomainUrlPrefState();
return true; return true;
} }
@@ -121,26 +163,8 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean ret = false; // actual updates are handled by the app link dropdown callback
final String key = preference.getKey(); return true;
if (KEY_OPEN_DOMAIN_URLS.equals(key)) {
final SwitchPreference pref = (SwitchPreference) preference;
final Boolean switchedOn = (Boolean) newValue;
int newState = switchedOn ?
INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS :
INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
final int userId = UserHandle.myUserId();
boolean success = mPm.updateIntentVerificationStatus(mPackageName, newState, userId);
if (success) {
// read back the state to ensure canonicality
newState = mPm.getIntentVerificationStatus(mPackageName, userId);
ret = (newState == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS);
pref.setChecked(ret);
} else {
Log.e(TAG, "Couldn't update intent verification status!");
}
}
return ret;
} }
@Override @Override