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