Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.content.Context; |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 20 | import android.content.Intent; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 21 | import android.content.pm.ActivityInfo; |
| 22 | import android.content.pm.ApplicationInfo; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 24 | import android.content.pm.ResolveInfo; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 25 | import android.os.Binder; |
| 26 | import android.os.Build; |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | import android.os.Looper; |
| 29 | import android.os.Message; |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 30 | import android.os.UserHandle; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 31 | import android.provider.MediaStore; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 32 | import android.system.ErrnoException; |
| 33 | import android.system.Os; |
| 34 | import android.system.OsConstants; |
| 35 | import android.system.StructStat; |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 36 | import android.util.Slog; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 37 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 38 | import com.android.internal.app.ResolverActivity; |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 39 | import com.android.internal.os.BackgroundThread; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 40 | import com.android.internal.util.DumpUtils; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 41 | |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 42 | import dalvik.system.DexFile; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 43 | import dalvik.system.VMRuntime; |
| 44 | |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 45 | import java.io.FileDescriptor; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 46 | import java.io.IOException; |
| 47 | import java.io.PrintWriter; |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 48 | import java.util.ArrayList; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * <p>PinnerService pins important files for key processes in memory.</p> |
| 52 | * <p>Files to pin are specified in the config_defaultPinnerServiceFiles |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 53 | * overlay.</p> |
| 54 | * <p>Pin the default camera application if specified in config_pinnerCameraApp.</p> |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 55 | */ |
| 56 | public final class PinnerService extends SystemService { |
| 57 | private static final boolean DEBUG = false; |
| 58 | private static final String TAG = "PinnerService"; |
| 59 | |
| 60 | private final Context mContext; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 61 | private final ArrayList<PinnedFile> mPinnedFiles = new ArrayList<PinnedFile>(); |
| 62 | private final ArrayList<PinnedFile> mPinnedCameraFiles = new ArrayList<PinnedFile>(); |
| 63 | private final boolean mShouldPinCamera; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 64 | |
| 65 | private BinderService mBinderService; |
| 66 | |
Philip Cuadra | ac39b96 | 2016-11-02 11:59:22 -0700 | [diff] [blame] | 67 | private final long MAX_CAMERA_PIN_SIZE = 80 * (1 << 20); //80MB max |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 68 | |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 69 | private PinnerHandler mPinnerHandler = null; |
| 70 | |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 71 | |
| 72 | public PinnerService(Context context) { |
| 73 | super(context); |
| 74 | |
| 75 | mContext = context; |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 76 | mShouldPinCamera = context.getResources().getBoolean( |
| 77 | com.android.internal.R.bool.config_pinnerCameraApp); |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 78 | mPinnerHandler = new PinnerHandler(BackgroundThread.get().getLooper()); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void onStart() { |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 83 | if (DEBUG) { |
| 84 | Slog.i(TAG, "Starting PinnerService"); |
| 85 | } |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 86 | mBinderService = new BinderService(); |
| 87 | publishBinderService("pinner", mBinderService); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 88 | |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 89 | mPinnerHandler.obtainMessage(PinnerHandler.PIN_ONSTART_MSG).sendToTarget(); |
| 90 | mPinnerHandler.obtainMessage(PinnerHandler.PIN_CAMERA_MSG, UserHandle.USER_SYSTEM, 0) |
| 91 | .sendToTarget(); |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 95 | * Pin camera on user switch. |
| 96 | * If more than one user is using the device |
| 97 | * each user may set a different preference for the camera app. |
| 98 | * Make sure that user's preference is pinned into memory. |
| 99 | */ |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 100 | @Override |
| 101 | public void onSwitchUser(int userHandle) { |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 102 | mPinnerHandler.obtainMessage(PinnerHandler.PIN_CAMERA_MSG, userHandle, 0).sendToTarget(); |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Handler for on start pinning message |
| 107 | */ |
| 108 | private void handlePinOnStart() { |
| 109 | // Files to pin come from the overlay and can be specified per-device config |
| 110 | String[] filesToPin = mContext.getResources().getStringArray( |
| 111 | com.android.internal.R.array.config_defaultPinnerServiceFiles); |
| 112 | synchronized(this) { |
| 113 | // Continue trying to pin remaining files even if there is a failure |
| 114 | for (int i = 0; i < filesToPin.length; i++){ |
| 115 | PinnedFile pf = pinFile(filesToPin[i], 0, 0, 0); |
| 116 | if (pf != null) { |
| 117 | mPinnedFiles.add(pf); |
| 118 | if (DEBUG) { |
| 119 | Slog.i(TAG, "Pinned file = " + pf.mFilename); |
| 120 | } |
| 121 | } else { |
| 122 | Slog.e(TAG, "Failed to pin file = " + filesToPin[i]); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Handler for camera pinning message |
| 130 | */ |
| 131 | private void handlePinCamera(int userHandle) { |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 132 | if (mShouldPinCamera) { |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 133 | synchronized(this) { |
| 134 | boolean success = pinCamera(userHandle); |
| 135 | if (!success) { |
| 136 | //this is not necessarily an error |
| 137 | if (DEBUG) { |
| 138 | Slog.v(TAG, "Failed to pin camera."); |
| 139 | } |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * determine if the camera app is already pinned by comparing the |
| 147 | * intent resolution to the pinned files list |
| 148 | */ |
| 149 | private boolean alreadyPinned(int userHandle) { |
| 150 | ApplicationInfo cameraInfo = getCameraInfo(userHandle); |
| 151 | if (cameraInfo == null ) { |
| 152 | return false; |
| 153 | } |
| 154 | for (int i = 0; i < mPinnedCameraFiles.size(); i++) { |
| 155 | if (mPinnedCameraFiles.get(i).mFilename.equals(cameraInfo.sourceDir)) { |
| 156 | if (DEBUG) { |
| 157 | Slog.v(TAG, "Camera is already pinned"); |
| 158 | } |
| 159 | return true; |
| 160 | } |
| 161 | } |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | private void unpinCameraApp() { |
| 166 | for (int i = 0; i < mPinnedCameraFiles.size(); i++) { |
| 167 | unpinFile(mPinnedCameraFiles.get(i)); |
| 168 | } |
| 169 | mPinnedCameraFiles.clear(); |
| 170 | } |
| 171 | |
| 172 | private boolean isResolverActivity(ActivityInfo info) { |
| 173 | return ResolverActivity.class.getName().equals(info.name); |
| 174 | } |
| 175 | |
| 176 | private ApplicationInfo getCameraInfo(int userHandle) { |
| 177 | // find the camera via an intent |
| 178 | // use INTENT_ACTION_STILL_IMAGE_CAMERA instead of _SECURE. On a |
| 179 | // device without a fbe enabled, the _SECURE intent will never get set. |
| 180 | Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 181 | PackageManager pm = mContext.getPackageManager(); |
Jeff Sharkey | 847bd85 | 2016-08-03 17:20:03 -0600 | [diff] [blame] | 182 | ResolveInfo cameraResolveInfo = pm.resolveActivityAsUser(cameraIntent, |
| 183 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 184 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
| 185 | userHandle); |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 186 | if (cameraResolveInfo == null ) { |
| 187 | //this is not necessarily an error |
| 188 | if (DEBUG) { |
| 189 | Slog.v(TAG, "Unable to resolve camera intent"); |
| 190 | } |
| 191 | return null; |
| 192 | } |
| 193 | |
| 194 | if (isResolverActivity(cameraResolveInfo.activityInfo)) |
| 195 | { |
Philip Cuadra | ac39b96 | 2016-11-02 11:59:22 -0700 | [diff] [blame] | 196 | if (DEBUG) { |
| 197 | Slog.v(TAG, "cameraIntent returned resolverActivity"); |
| 198 | } |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 199 | return null; |
| 200 | } |
| 201 | |
| 202 | return cameraResolveInfo.activityInfo.applicationInfo; |
| 203 | } |
| 204 | |
| 205 | private boolean pinCamera(int userHandle){ |
| 206 | //we may have already pinned a camera app. If we've pinned this |
| 207 | //camera app, we're done. otherwise, unpin and pin the new app |
| 208 | if (alreadyPinned(userHandle)){ |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | ApplicationInfo cameraInfo = getCameraInfo(userHandle); |
| 213 | if (cameraInfo == null) { |
| 214 | return false; |
| 215 | } |
| 216 | |
| 217 | //unpin after checking that the camera intent has resolved |
| 218 | //this prevents us from thrashing when switching users with |
| 219 | //FBE enabled, because the intent won't resolve until the unlock |
| 220 | unpinCameraApp(); |
| 221 | |
| 222 | //pin APK |
| 223 | String camAPK = cameraInfo.sourceDir; |
| 224 | PinnedFile pf = pinFile(camAPK, 0, 0, MAX_CAMERA_PIN_SIZE); |
| 225 | if (pf == null) { |
| 226 | Slog.e(TAG, "Failed to pin " + camAPK); |
| 227 | return false; |
| 228 | } |
| 229 | if (DEBUG) { |
| 230 | Slog.i(TAG, "Pinned " + pf.mFilename); |
| 231 | } |
| 232 | mPinnedCameraFiles.add(pf); |
| 233 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 234 | // determine the ABI from either ApplicationInfo or Build |
| 235 | String arch = "arm"; |
| 236 | if (cameraInfo.primaryCpuAbi != null |
| 237 | && VMRuntime.is64BitAbi(cameraInfo.primaryCpuAbi)) { |
| 238 | arch = arch + "64"; |
| 239 | } else { |
| 240 | if (VMRuntime.is64BitAbi(Build.SUPPORTED_ABIS[0])) { |
| 241 | arch = arch + "64"; |
| 242 | } |
| 243 | } |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 244 | |
| 245 | // get the path to the odex or oat file |
| 246 | String baseCodePath = cameraInfo.getBaseCodePath(); |
Calin Juravle | 128721a | 2017-05-15 20:20:50 -0700 | [diff] [blame^] | 247 | String[] files = null; |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 248 | try { |
Calin Juravle | 128721a | 2017-05-15 20:20:50 -0700 | [diff] [blame^] | 249 | files = DexFile.getDexFileOutputPaths(baseCodePath, arch); |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 250 | } catch (IOException ioe) {} |
Calin Juravle | 128721a | 2017-05-15 20:20:50 -0700 | [diff] [blame^] | 251 | if (files == null) { |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
| 255 | //not pinning the oat/odex is not a fatal error |
Calin Juravle | 128721a | 2017-05-15 20:20:50 -0700 | [diff] [blame^] | 256 | for (String file : files) { |
| 257 | pf = pinFile(file, 0, 0, MAX_CAMERA_PIN_SIZE); |
| 258 | if (pf != null) { |
| 259 | mPinnedCameraFiles.add(pf); |
| 260 | if (DEBUG) { |
| 261 | Slog.i(TAG, "Pinned " + pf.mFilename); |
| 262 | } |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
Philip Cuadra | d9bd884 | 2016-07-12 17:29:38 -0700 | [diff] [blame] | 265 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /** mlock length bytes of fileToPin in memory, starting at offset |
| 271 | * length == 0 means pin from offset to end of file |
| 272 | * maxSize == 0 means infinite |
| 273 | */ |
| 274 | private static PinnedFile pinFile(String fileToPin, long offset, long length, long maxSize) { |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 275 | FileDescriptor fd = new FileDescriptor(); |
| 276 | try { |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 277 | fd = Os.open(fileToPin, |
| 278 | OsConstants.O_RDONLY | OsConstants.O_CLOEXEC | OsConstants.O_NOFOLLOW, |
| 279 | OsConstants.O_RDONLY); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 280 | |
| 281 | StructStat sb = Os.fstat(fd); |
| 282 | |
| 283 | if (offset + length > sb.st_size) { |
| 284 | Os.close(fd); |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 285 | Slog.e(TAG, "Failed to pin file " + fileToPin + |
| 286 | ", request extends beyond end of file. offset + length = " |
| 287 | + (offset + length) + ", file length = " + sb.st_size); |
| 288 | return null; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | if (length == 0) { |
| 292 | length = sb.st_size - offset; |
| 293 | } |
| 294 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 295 | if (maxSize > 0 && length > maxSize) { |
| 296 | Slog.e(TAG, "Could not pin file " + fileToPin + |
| 297 | ", size = " + length + ", maxSize = " + maxSize); |
| 298 | Os.close(fd); |
| 299 | return null; |
| 300 | } |
| 301 | |
| 302 | long address = Os.mmap(0, length, OsConstants.PROT_READ, |
| 303 | OsConstants.MAP_PRIVATE, fd, offset); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 304 | Os.close(fd); |
| 305 | |
| 306 | Os.mlock(address, length); |
| 307 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 308 | return new PinnedFile(address, length, fileToPin); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 309 | } catch (ErrnoException e) { |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 310 | Slog.e(TAG, "Could not pin file " + fileToPin + " with error " + e.getMessage()); |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 311 | if(fd.valid()) { |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 312 | try { |
| 313 | Os.close(fd); |
| 314 | } |
| 315 | catch (ErrnoException eClose) { |
| 316 | Slog.e(TAG, "Failed to close fd, error = " + eClose.getMessage()); |
| 317 | } |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 318 | } |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 319 | return null; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 323 | private static boolean unpinFile(PinnedFile pf) { |
| 324 | try { |
| 325 | Os.munlock(pf.mAddress, pf.mLength); |
| 326 | } catch (ErrnoException e) { |
| 327 | Slog.e(TAG, "Failed to unpin file " + pf.mFilename + " with error " + e.getMessage()); |
| 328 | return false; |
| 329 | } |
| 330 | if (DEBUG) { |
| 331 | Slog.i(TAG, "Unpinned file " + pf.mFilename ); |
| 332 | } |
| 333 | return true; |
| 334 | } |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 335 | |
| 336 | private final class BinderService extends Binder { |
| 337 | @Override |
| 338 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 339 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 340 | pw.println("Pinned Files:"); |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 341 | synchronized(this) { |
| 342 | for (int i = 0; i < mPinnedFiles.size(); i++) { |
| 343 | pw.println(mPinnedFiles.get(i).mFilename); |
| 344 | } |
| 345 | for (int i = 0; i < mPinnedCameraFiles.size(); i++) { |
| 346 | pw.println(mPinnedCameraFiles.get(i).mFilename); |
| 347 | } |
Philip Cuadra | 7cb2f8b | 2016-06-15 16:23:43 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | private static class PinnedFile { |
| 353 | long mAddress; |
| 354 | long mLength; |
| 355 | String mFilename; |
| 356 | |
| 357 | PinnedFile(long address, long length, String filename) { |
| 358 | mAddress = address; |
| 359 | mLength = length; |
| 360 | mFilename = filename; |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
Philip Cuadra | a95cea0 | 2016-07-06 16:00:32 -0700 | [diff] [blame] | 363 | |
| 364 | final class PinnerHandler extends Handler { |
| 365 | static final int PIN_CAMERA_MSG = 4000; |
| 366 | static final int PIN_ONSTART_MSG = 4001; |
| 367 | |
| 368 | public PinnerHandler(Looper looper) { |
| 369 | super(looper, null, true); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void handleMessage(Message msg) { |
| 374 | switch (msg.what) { |
| 375 | |
| 376 | case PIN_CAMERA_MSG: |
| 377 | { |
| 378 | handlePinCamera(msg.arg1); |
| 379 | } |
| 380 | break; |
| 381 | |
| 382 | case PIN_ONSTART_MSG: |
| 383 | { |
| 384 | handlePinOnStart(); |
| 385 | } |
| 386 | break; |
| 387 | |
| 388 | default: |
| 389 | super.handleMessage(msg); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
Philip Cuadra | 7bd0fdd | 2016-04-28 15:26:49 -0700 | [diff] [blame] | 394 | } |