Bug 1312686 - Link "default browser" setting to app info screen on Android 7+; r?sebastian draft
authorbrainbreaker <gautamprajapati06@gmail.com>
Wed, 15 Feb 2017 02:27:26 +0530
changeset 484131 1873ce0eccb38ebf46293dbed04c9e3853d88437
parent 484130 c5a25b056d1e66fcaf67d680abea5a80d5944092
child 545718 f96c492fdebed36fe8d01d5d43d87cef47c95ffa
push id45399
push userbmo:gautamprajapati06@gmail.com
push dateTue, 14 Feb 2017 21:11:35 +0000
reviewerssebastian
bugs1312686
milestone54.0a1
Bug 1312686 - Link "default browser" setting to app info screen on Android 7+; r?sebastian Added support for changing default browser by opening settings screen in API Levels >=24. MozReview-Commit-ID: 5rxJm6hQQ4A
mobile/android/base/AppConstants.java.in
mobile/android/base/java/org/mozilla/gecko/preferences/LinkPreference.java
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -47,16 +47,17 @@ public class AppConstants {
          * If MIN_SDK_VERSION is greater than or equal to the number, there
          * is no need to do the runtime check.
          */
         public static final boolean feature16Plus = MIN_SDK_VERSION >= 16 || (MAX_SDK_VERSION >= 16 && Build.VERSION.SDK_INT >= 16);
         public static final boolean feature17Plus = MIN_SDK_VERSION >= 17 || (MAX_SDK_VERSION >= 17 && Build.VERSION.SDK_INT >= 17);
         public static final boolean feature19Plus = MIN_SDK_VERSION >= 19 || (MAX_SDK_VERSION >= 19 && Build.VERSION.SDK_INT >= 19);
         public static final boolean feature20Plus = MIN_SDK_VERSION >= 20 || (MAX_SDK_VERSION >= 20 && Build.VERSION.SDK_INT >= 20);
         public static final boolean feature21Plus = MIN_SDK_VERSION >= 21 || (MAX_SDK_VERSION >= 21 && Build.VERSION.SDK_INT >= 21);
+        public static final boolean feature24Plus = MIN_SDK_VERSION >= 24 || (MAX_SDK_VERSION >= 24 && Build.VERSION.SDK_INT >= 24);
 
         /*
          * If our MIN_SDK_VERSION is 14 or higher, we must be an ICS device.
          * If our MAX_SDK_VERSION is lower than ICS, we must not be an ICS device.
          * Otherwise, we need a range check.
          */
         public static final boolean preMarshmallow = MAX_SDK_VERSION < 23 || (MIN_SDK_VERSION < 23 && Build.VERSION.SDK_INT < 23);
         public static final boolean preLollipop = MAX_SDK_VERSION < 21 || (MIN_SDK_VERSION < 21 && Build.VERSION.SDK_INT < 21);
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/LinkPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/LinkPreference.java
@@ -1,35 +1,45 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.preferences;
 
-import org.mozilla.gecko.Tabs;
-
 import android.content.Context;
+import android.content.Intent;
 import android.preference.Preference;
 import android.util.AttributeSet;
 
+import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.Tabs;
+
 class LinkPreference extends Preference {
     private String mUrl;
 
     public LinkPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
         mUrl = attrs.getAttributeValue(null, "url");
     }
     public LinkPreference(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         mUrl = attrs.getAttributeValue(null, "url");
     }
 
     public void setUrl(String url) {
         mUrl = url;
     }
 
+    /**
+     * Open Default apps screen of Settings for API Levels>=24. Support URL will open for lower API levels
+     */
     @Override
     protected void onClick() {
-        Tabs.getInstance().loadUrlInTab(mUrl);
-        callChangeListener(mUrl);
+        if (AppConstants.Versions.feature24Plus) {
+            Intent changeDefaultApps = new Intent("android.settings.MANAGE_DEFAULT_APPS_SETTINGS");
+            getContext().startActivity(changeDefaultApps);
+        } else {
+            Tabs.getInstance().loadUrlInTab(mUrl);
+            callChangeListener(mUrl);
+        }
     }
 }