Skip to content

Commit

Permalink
Remove Play Stor button: not usable for non-existent package
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Miś <foss@patrykmis.com>
  • Loading branch information
PatrykMis committed Mar 24, 2024
1 parent ac42022 commit d392275
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

assignNewFeaturesIntent();

showTalkBackVersion();

if (SettingsUtils.allowLinksOutOfSettings(context) || formFactorUtils.isAndroidTv()) {
assignTtsSettingsIntent();

// We should never try to open the play store in WebActivity.
assignPlayStoreIntentToPreference();
} else {
// During setup, do not allow access to web.
PreferenceSettingsUtils.hidePreference(
context, getPreferenceScreen(), R.string.pref_play_store_key);
removeCategory(R.string.pref_category_legal_and_privacy_key);

// During setup, do not allow access to other apps via custom-labeling.
Expand Down Expand Up @@ -200,43 +193,6 @@ private void removeCategory(int categoryKeyId) {
}
}

private void assignPlayStoreIntentToPreference() {

Preference pref = findPreferenceByResId(R.string.pref_play_store_key);
if (pref == null) {
return;
}

PreferenceGroup category =
(PreferenceGroup) findPreferenceByResId(R.string.pref_category_general_key);
if (!getResources().getBoolean(R.bool.show_play_store)) {
if (category != null) {
category.removePreference(pref);
}
return;
}

String packageName = PackageManagerUtils.TALKBACK_PACKAGE;

Uri uri;
if (formFactorUtils.isAndroidWear()) {
// Only for watches, try the "market://" URL first. If there is a Play Store on the
// device, this should succeed. Only for LE devices, there will be no Play Store.
uri = Uri.parse("market://details?id=" + packageName);
} else {
uri = Uri.parse("https://play.google.com/store/apps/details?id=" + packageName);
}

Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (canHandleIntent(intent)) {
pref.setIntent(intent);
} else {
if (category != null) {
category.removePreference(pref);
}
}
}

private boolean canHandleIntent(Intent intent) {
PackageManager manager = context.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
Expand Down Expand Up @@ -360,28 +316,6 @@ private void fixListSummaries(PreferenceGroup group) {
}
}

/** Show TalkBack version in the Play Store button. */
private void showTalkBackVersion() {
PackageInfo packageInfo = getPackageInfo(context);
if (packageInfo == null) {
return;
}
final Preference playStoreButton = findPreferenceByResId(R.string.pref_play_store_key);
if (playStoreButton == null) {
return;
}
Pattern pattern = Pattern.compile("[0-9]+\\.[0-9]+");
Matcher matcher = pattern.matcher(String.valueOf(packageInfo.versionName));
String summary;
if (matcher.find()) {
summary = getString(R.string.summary_pref_play_store, matcher.group());
} else {
summary =
getString(R.string.summary_pref_play_store, String.valueOf(packageInfo.versionName));
}
playStoreButton.setSummary(summary);
}

/**
* Listens for preference changes and updates the summary to reflect the current setting. This
* shouldn't be necessary, since preferences are supposed to automatically do this when the
Expand Down
4 changes: 0 additions & 4 deletions talkback/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,5 @@
android:title="@string/title_pref_advanced_settings"
android:fragment="com.google.android.accessibility.talkback.preference.base.AdvancedSettingFragment" >
</com.google.android.accessibility.utils.preference.AccessibilitySuitePreference>
<com.google.android.accessibility.utils.preference.AccessibilitySuitePreference
android:key="@string/pref_play_store_key"
android:title="@string/title_pref_play_store">
</com.google.android.accessibility.utils.preference.AccessibilitySuitePreference>
</com.google.android.accessibility.utils.preference.AccessibilitySuitePreferenceCategory>
</PreferenceScreen>

0 comments on commit d392275

Please sign in to comment.