Craig Mautner | c2c0a61 | 2014-02-20 20:25:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 18 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 19 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 20 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 21 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 22 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 23 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 24 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 25 | import java.io.File; |
| 26 | import java.io.FileInputStream; |
| 27 | import java.io.FileOutputStream; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 28 | import java.nio.charset.StandardCharsets; |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 29 | import java.util.HashMap; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 30 | import java.util.Iterator; |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 31 | import java.util.Map; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 32 | |
| 33 | import org.xmlpull.v1.XmlPullParser; |
| 34 | import org.xmlpull.v1.XmlPullParserException; |
| 35 | import org.xmlpull.v1.XmlSerializer; |
| 36 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 37 | import com.android.internal.util.FastXmlSerializer; |
| 38 | |
| 39 | import android.app.ActivityManager; |
| 40 | import android.app.AppGlobals; |
| 41 | import android.content.pm.ApplicationInfo; |
| 42 | import android.content.pm.IPackageManager; |
| 43 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 44 | import android.content.res.Configuration; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 45 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 46 | import android.os.Looper; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 47 | import android.os.Message; |
| 48 | import android.os.RemoteException; |
Dianne Hackborn | 39606a0 | 2012-07-31 17:54:35 -0700 | [diff] [blame] | 49 | import android.util.AtomicFile; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 50 | import android.util.Slog; |
| 51 | import android.util.Xml; |
| 52 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 53 | public final class CompatModePackages { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 54 | private static final String TAG = TAG_WITH_CLASS_NAME ? "CompatModePackages" : TAG_ATM; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 55 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 56 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 57 | private final ActivityTaskManagerService mService; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 58 | private final AtomicFile mFile; |
| 59 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 60 | // Compatibility state: no longer ask user to select the mode. |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 61 | private static final int COMPAT_FLAG_DONT_ASK = 1<<0; |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 62 | // Compatibility state: compatibility mode is enabled. |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 63 | private static final int COMPAT_FLAG_ENABLED = 1<<1; |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 64 | |
| 65 | private final HashMap<String, Integer> mPackages = new HashMap<String, Integer>(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 66 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 67 | private static final int MSG_WRITE = 300; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 68 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 69 | private final CompatHandler mHandler; |
| 70 | |
| 71 | private final class CompatHandler extends Handler { |
| 72 | public CompatHandler(Looper looper) { |
| 73 | super(looper, null, true); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void handleMessage(Message msg) { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 78 | switch (msg.what) { |
| 79 | case MSG_WRITE: |
| 80 | saveCompatModes(); |
| 81 | break; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | }; |
| 85 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 86 | public CompatModePackages(ActivityTaskManagerService service, File systemDir, Handler handler) { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 87 | mService = service; |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 88 | mFile = new AtomicFile(new File(systemDir, "packages-compat.xml"), "compat-mode"); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 89 | mHandler = new CompatHandler(handler.getLooper()); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 90 | |
| 91 | FileInputStream fis = null; |
| 92 | try { |
| 93 | fis = mFile.openRead(); |
| 94 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 95 | parser.setInput(fis, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 96 | int eventType = parser.getEventType(); |
Narayan Kamath | 2ac3cb7 | 2014-01-06 11:31:35 +0000 | [diff] [blame] | 97 | while (eventType != XmlPullParser.START_TAG && |
| 98 | eventType != XmlPullParser.END_DOCUMENT) { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 99 | eventType = parser.next(); |
| 100 | } |
Narayan Kamath | 2ac3cb7 | 2014-01-06 11:31:35 +0000 | [diff] [blame] | 101 | if (eventType == XmlPullParser.END_DOCUMENT) { |
| 102 | return; |
| 103 | } |
| 104 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 105 | String tagName = parser.getName(); |
| 106 | if ("compat-packages".equals(tagName)) { |
| 107 | eventType = parser.next(); |
| 108 | do { |
| 109 | if (eventType == XmlPullParser.START_TAG) { |
| 110 | tagName = parser.getName(); |
| 111 | if (parser.getDepth() == 2) { |
| 112 | if ("pkg".equals(tagName)) { |
| 113 | String pkg = parser.getAttributeValue(null, "name"); |
| 114 | if (pkg != null) { |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 115 | String mode = parser.getAttributeValue(null, "mode"); |
| 116 | int modeInt = 0; |
| 117 | if (mode != null) { |
| 118 | try { |
| 119 | modeInt = Integer.parseInt(mode); |
| 120 | } catch (NumberFormatException e) { |
| 121 | } |
| 122 | } |
| 123 | mPackages.put(pkg, modeInt); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | eventType = parser.next(); |
| 129 | } while (eventType != XmlPullParser.END_DOCUMENT); |
| 130 | } |
| 131 | } catch (XmlPullParserException e) { |
| 132 | Slog.w(TAG, "Error reading compat-packages", e); |
| 133 | } catch (java.io.IOException e) { |
| 134 | if (fis != null) Slog.w(TAG, "Error reading compat-packages", e); |
| 135 | } finally { |
| 136 | if (fis != null) { |
| 137 | try { |
| 138 | fis.close(); |
| 139 | } catch (java.io.IOException e1) { |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 145 | public HashMap<String, Integer> getPackages() { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 146 | return mPackages; |
| 147 | } |
| 148 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 149 | private int getPackageFlags(String packageName) { |
| 150 | Integer flags = mPackages.get(packageName); |
| 151 | return flags != null ? flags : 0; |
| 152 | } |
| 153 | |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 154 | public void handlePackageDataClearedLocked(String packageName) { |
| 155 | // User has explicitly asked to clear all associated data. |
| 156 | removePackage(packageName); |
| 157 | } |
| 158 | |
| 159 | public void handlePackageUninstalledLocked(String packageName) { |
| 160 | // Clear settings when app is uninstalled since this is an explicit |
| 161 | // signal from the user to remove the app and all associated data. |
| 162 | removePackage(packageName); |
| 163 | } |
| 164 | |
| 165 | private void removePackage(String packageName) { |
| 166 | if (mPackages.containsKey(packageName)) { |
| 167 | mPackages.remove(packageName); |
| 168 | scheduleWrite(); |
| 169 | } |
| 170 | } |
| 171 | |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 172 | public void handlePackageAddedLocked(String packageName, boolean updated) { |
| 173 | ApplicationInfo ai = null; |
| 174 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 175 | ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0); |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 176 | } catch (RemoteException e) { |
| 177 | } |
| 178 | if (ai == null) { |
| 179 | return; |
| 180 | } |
| 181 | CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai); |
| 182 | final boolean mayCompat = !ci.alwaysSupportsScreen() |
| 183 | && !ci.neverSupportsScreen(); |
| 184 | |
Dianne Hackborn | a955170 | 2011-06-14 21:05:03 -0700 | [diff] [blame] | 185 | if (updated) { |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 186 | // Update -- if the app no longer can run in compat mode, clear |
| 187 | // any current settings for it. |
| 188 | if (!mayCompat && mPackages.containsKey(packageName)) { |
| 189 | mPackages.remove(packageName); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 190 | scheduleWrite(); |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 195 | private void scheduleWrite() { |
| 196 | mHandler.removeMessages(MSG_WRITE); |
| 197 | Message msg = mHandler.obtainMessage(MSG_WRITE); |
| 198 | mHandler.sendMessageDelayed(msg, 10000); |
| 199 | } |
| 200 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 201 | public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 202 | final Configuration globalConfig = mService.getGlobalConfiguration(); |
| 203 | CompatibilityInfo ci = new CompatibilityInfo(ai, globalConfig.screenLayout, |
| 204 | globalConfig.smallestScreenWidthDp, |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 205 | (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 206 | //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci); |
| 207 | return ci; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 210 | public int computeCompatModeLocked(ApplicationInfo ai) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 211 | final boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0; |
| 212 | final Configuration globalConfig = mService.getGlobalConfiguration(); |
| 213 | final CompatibilityInfo info = new CompatibilityInfo(ai, globalConfig.screenLayout, |
| 214 | globalConfig.smallestScreenWidthDp, enabled); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 215 | if (info.alwaysSupportsScreen()) { |
| 216 | return ActivityManager.COMPAT_MODE_NEVER; |
| 217 | } |
| 218 | if (info.neverSupportsScreen()) { |
| 219 | return ActivityManager.COMPAT_MODE_ALWAYS; |
| 220 | } |
| 221 | return enabled ? ActivityManager.COMPAT_MODE_ENABLED |
| 222 | : ActivityManager.COMPAT_MODE_DISABLED; |
| 223 | } |
| 224 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 225 | public boolean getPackageAskCompatModeLocked(String packageName) { |
| 226 | return (getPackageFlags(packageName)&COMPAT_FLAG_DONT_ASK) == 0; |
| 227 | } |
| 228 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 229 | public void setPackageAskCompatModeLocked(String packageName, boolean ask) { |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 230 | setPackageFlagLocked(packageName, COMPAT_FLAG_DONT_ASK, ask); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 233 | private void setPackageFlagLocked(String packageName, int flag, boolean set) { |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 234 | final int curFlags = getPackageFlags(packageName); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 235 | final int newFlags = set ? (curFlags & ~flag) : (curFlags | flag); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 236 | if (curFlags != newFlags) { |
| 237 | if (newFlags != 0) { |
| 238 | mPackages.put(packageName, newFlags); |
| 239 | } else { |
| 240 | mPackages.remove(packageName); |
| 241 | } |
| 242 | scheduleWrite(); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 246 | public int getPackageScreenCompatModeLocked(String packageName) { |
| 247 | ApplicationInfo ai = null; |
| 248 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 249 | ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 250 | } catch (RemoteException e) { |
| 251 | } |
| 252 | if (ai == null) { |
| 253 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 254 | } |
| 255 | return computeCompatModeLocked(ai); |
| 256 | } |
| 257 | |
| 258 | public void setPackageScreenCompatModeLocked(String packageName, int mode) { |
| 259 | ApplicationInfo ai = null; |
| 260 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 261 | ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 262 | } catch (RemoteException e) { |
| 263 | } |
| 264 | if (ai == null) { |
| 265 | Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName); |
| 266 | return; |
| 267 | } |
| 268 | setPackageScreenCompatModeLocked(ai, mode); |
| 269 | } |
| 270 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 271 | void setPackageScreenCompatModeLocked(ApplicationInfo ai, int mode) { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 272 | final String packageName = ai.packageName; |
| 273 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 274 | int curFlags = getPackageFlags(packageName); |
| 275 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 276 | boolean enable; |
| 277 | switch (mode) { |
| 278 | case ActivityManager.COMPAT_MODE_DISABLED: |
| 279 | enable = false; |
| 280 | break; |
| 281 | case ActivityManager.COMPAT_MODE_ENABLED: |
| 282 | enable = true; |
| 283 | break; |
| 284 | case ActivityManager.COMPAT_MODE_TOGGLE: |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 285 | enable = (curFlags&COMPAT_FLAG_ENABLED) == 0; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 286 | break; |
| 287 | default: |
| 288 | Slog.w(TAG, "Unknown screen compat mode req #" + mode + "; ignoring"); |
| 289 | return; |
| 290 | } |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 291 | |
| 292 | int newFlags = curFlags; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 293 | if (enable) { |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 294 | newFlags |= COMPAT_FLAG_ENABLED; |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 295 | } else { |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 296 | newFlags &= ~COMPAT_FLAG_ENABLED; |
| 297 | } |
| 298 | |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 299 | CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai); |
| 300 | if (ci.alwaysSupportsScreen()) { |
| 301 | Slog.w(TAG, "Ignoring compat mode change of " + packageName |
| 302 | + "; compatibility never needed"); |
| 303 | newFlags = 0; |
| 304 | } |
| 305 | if (ci.neverSupportsScreen()) { |
| 306 | Slog.w(TAG, "Ignoring compat mode change of " + packageName |
| 307 | + "; compatibility always needed"); |
| 308 | newFlags = 0; |
| 309 | } |
| 310 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 311 | if (newFlags != curFlags) { |
| 312 | if (newFlags != 0) { |
| 313 | mPackages.put(packageName, newFlags); |
| 314 | } else { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 315 | mPackages.remove(packageName); |
| 316 | } |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 317 | |
| 318 | // Need to get compatibility info in new state. |
| 319 | ci = compatibilityInfoForPackageLocked(ai); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 320 | |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 321 | scheduleWrite(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 322 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 323 | final ActivityStack stack = mService.getTopDisplayFocusedStack(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 324 | ActivityRecord starting = stack.restartPackage(packageName); |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 325 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 326 | // Tell all processes that loaded this package about the change. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 327 | for (int i = mService.mPidMap.size() - 1; i >= 0; i--) { |
| 328 | final WindowProcessController app = mService.mPidMap.valueAt(i); |
| 329 | if (!app.mPkgList.contains(packageName)) { |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 330 | continue; |
| 331 | } |
| 332 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 333 | if (app.hasThread()) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 334 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Sending to proc " |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 335 | + app.mName + " new compat " + ci); |
| 336 | app.getThread().updatePackageCompatibilityInfo(packageName, ci); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 337 | } |
| 338 | } catch (Exception e) { |
| 339 | } |
| 340 | } |
| 341 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 342 | if (starting != null) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 343 | starting.ensureActivityConfiguration(0 /* globalChanges */, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 344 | false /* preserveWindow */); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 345 | // And we need to make sure at this point that all other activities |
| 346 | // are made visible with the correct configuration. |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 347 | stack.ensureActivitiesVisibleLocked(starting, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 352 | private void saveCompatModes() { |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 353 | HashMap<String, Integer> pkgs; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 354 | synchronized (mService.mGlobalLock) { |
| 355 | pkgs = new HashMap<>(mPackages); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | FileOutputStream fos = null; |
| 359 | |
| 360 | try { |
| 361 | fos = mFile.startWrite(); |
| 362 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 363 | out.setOutput(fos, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 364 | out.startDocument(null, true); |
| 365 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 366 | out.startTag(null, "compat-packages"); |
| 367 | |
| 368 | final IPackageManager pm = AppGlobals.getPackageManager(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 369 | final Configuration globalConfig = mService.getGlobalConfiguration(); |
| 370 | final int screenLayout = globalConfig.screenLayout; |
| 371 | final int smallestScreenWidthDp = globalConfig.smallestScreenWidthDp; |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 372 | final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 373 | while (it.hasNext()) { |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 374 | Map.Entry<String, Integer> entry = it.next(); |
| 375 | String pkg = entry.getKey(); |
| 376 | int mode = entry.getValue(); |
| 377 | if (mode == 0) { |
| 378 | continue; |
| 379 | } |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 380 | ApplicationInfo ai = null; |
| 381 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 382 | ai = pm.getApplicationInfo(pkg, 0, 0); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 383 | } catch (RemoteException e) { |
| 384 | } |
| 385 | if (ai == null) { |
| 386 | continue; |
| 387 | } |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 388 | CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, |
| 389 | smallestScreenWidthDp, false); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 390 | if (info.alwaysSupportsScreen()) { |
| 391 | continue; |
| 392 | } |
| 393 | if (info.neverSupportsScreen()) { |
| 394 | continue; |
| 395 | } |
| 396 | out.startTag(null, "pkg"); |
| 397 | out.attribute(null, "name", pkg); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 398 | out.attribute(null, "mode", Integer.toString(mode)); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 399 | out.endTag(null, "pkg"); |
| 400 | } |
| 401 | |
| 402 | out.endTag(null, "compat-packages"); |
| 403 | out.endDocument(); |
| 404 | |
| 405 | mFile.finishWrite(fos); |
| 406 | } catch (java.io.IOException e1) { |
| 407 | Slog.w(TAG, "Error writing compat packages", e1); |
| 408 | if (fos != null) { |
| 409 | mFile.failWrite(fos); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | } |