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