packages/apps/Taskbar
Révision | 8db44932f33c88f07d45dcfb0af77d953c4a6b72 (tree) |
---|---|
l'heure | 2020-03-23 12:10:40 |
Auteur | Braden Farmer <farmerbb@gmai...> |
Commiter | Braden Farmer |
Laying some of the groundwork for the additional desktop mode settings
@@ -1214,15 +1214,7 @@ public class U { | ||
1214 | 1214 | if(context.getPackageName().equals(BuildConfig.ANDROIDX86_APPLICATION_ID)) |
1215 | 1215 | return true; |
1216 | 1216 | |
1217 | - PackageManager pm = context.getPackageManager(); | |
1218 | - try { | |
1219 | - pm.getPackageInfo(BuildConfig.SUPPORT_APPLICATION_ID, 0); | |
1220 | - return pm.checkSignatures(BuildConfig.SUPPORT_APPLICATION_ID, context.getPackageName()) == PackageManager.SIGNATURE_MATCH | |
1221 | - && context.getPackageName().equals(BuildConfig.BASE_APPLICATION_ID) | |
1222 | - && isSystemApp(context); | |
1223 | - } catch (PackageManager.NameNotFoundException e) { | |
1224 | - return false; | |
1225 | - } | |
1217 | + return hasSupportLibrary(context, 0); | |
1226 | 1218 | } |
1227 | 1219 | |
1228 | 1220 | public static boolean hasSupportLibrary(Context context, int minVersion) { |
@@ -1320,18 +1312,38 @@ public class U { | ||
1320 | 1312 | } |
1321 | 1313 | |
1322 | 1314 | public static void showHideNavigationBar(Context context, boolean show) { |
1315 | + if(!isDesktopModeActive(context) | |
1316 | + && !isBlissOs(context) | |
1317 | + && !hasSupportLibrary(context, 7)) { | |
1318 | + return; | |
1319 | + } | |
1320 | + | |
1321 | + int displayID = getDisplayID(); | |
1322 | + int value = show ? 0 : getNavbarHeight(context) * -1; | |
1323 | + | |
1324 | + if(hasWriteSecureSettingsPermission(context)) { | |
1325 | + try { | |
1326 | + setOverscan(displayID, value); | |
1327 | + return; | |
1328 | + } catch (Exception e) { | |
1329 | + // Fallback to next method | |
1330 | + } | |
1331 | + } | |
1332 | + | |
1323 | 1333 | if(hasSupportLibrary(context, 7)) { |
1324 | 1334 | Intent intent = new Intent(BuildConfig.SUPPORT_APPLICATION_ID + ".CHANGE_OVERSCAN"); |
1325 | 1335 | intent.setPackage(BuildConfig.SUPPORT_APPLICATION_ID); |
1326 | 1336 | |
1327 | - intent.putExtra("display_id", getDisplayID()); | |
1328 | - intent.putExtra("value", show ? 0 : getNavbarHeight(context) * -1); | |
1337 | + intent.putExtra("display_id", displayID); | |
1338 | + intent.putExtra("value", value); | |
1329 | 1339 | |
1330 | 1340 | context.sendBroadcast(intent); |
1331 | 1341 | return; |
1332 | 1342 | } |
1333 | 1343 | |
1334 | 1344 | // Show or hide the system navigation bar on Bliss-x86 |
1345 | + if(!isBlissOs(context)) return; | |
1346 | + | |
1335 | 1347 | try { |
1336 | 1348 | if(getCurrentApiVersion() >= 28.0f) |
1337 | 1349 | Settings.Secure.putInt(context.getContentResolver(), "navigation_bar_visible", show ? 1 : 0); |
@@ -1857,10 +1869,43 @@ public class U { | ||
1857 | 1869 | && !pref.getBoolean("launcher", false); |
1858 | 1870 | } |
1859 | 1871 | |
1872 | + // TODO remove this in favor of the existing getDisplayID method? | |
1860 | 1873 | public static int getExternalDisplayID(Context context) { |
1861 | 1874 | DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); |
1862 | 1875 | Display[] displays = dm.getDisplays(); |
1863 | 1876 | |
1864 | 1877 | return displays[displays.length - 1].getDisplayId(); |
1865 | 1878 | } |
1879 | + | |
1880 | + @SuppressLint("PrivateApi") | |
1881 | + private static Object getWindowManagerService() throws Exception { | |
1882 | + return Class.forName("android.view.WindowManagerGlobal") | |
1883 | + .getMethod("getWindowManagerService") | |
1884 | + .invoke(null); | |
1885 | + } | |
1886 | + | |
1887 | + @SuppressLint("PrivateApi") | |
1888 | + private static void setDensity(int displayID, String value) throws Exception { | |
1889 | + // From android.os.UserHandle | |
1890 | + final int USER_CURRENT_OR_SELF = -3; | |
1891 | + | |
1892 | + if(value.equals("reset")) { | |
1893 | + Class.forName("android.view.IWindowManager") | |
1894 | + .getMethod("clearForcedDisplayDensityForUser", int.class, int.class) | |
1895 | + .invoke(getWindowManagerService(), displayID, USER_CURRENT_OR_SELF); | |
1896 | + } else { | |
1897 | + int density = Integer.parseInt(value); | |
1898 | + | |
1899 | + Class.forName("android.view.IWindowManager") | |
1900 | + .getMethod("setForcedDisplayDensityForUser", int.class, int.class, int.class) | |
1901 | + .invoke(getWindowManagerService(), displayID, density, USER_CURRENT_OR_SELF); | |
1902 | + } | |
1903 | + } | |
1904 | + | |
1905 | + @SuppressLint("PrivateApi") | |
1906 | + private static void setOverscan(int displayID, int value) throws Exception { | |
1907 | + Class.forName("android.view.IWindowManager") | |
1908 | + .getMethod("setOverscan", int.class, int.class, int.class, int.class, int.class) | |
1909 | + .invoke(getWindowManagerService(), displayID, 0, 0, 0, value); | |
1910 | + } | |
1866 | 1911 | } |
@@ -12,7 +12,7 @@ public class TaskbarApplication extends Application { | ||
12 | 12 | protected void attachBaseContext(Context base) { |
13 | 13 | super.attachBaseContext(base); |
14 | 14 | |
15 | - if(U.getCurrentApiVersion() > 29.0f) | |
15 | + if(U.getCurrentApiVersion() > 29.0f || U.isDesktopModeSupported(base)) | |
16 | 16 | Reflection.unseal(base); |
17 | 17 | } |
18 | 18 | } |
\ No newline at end of file |