Loading AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -337,6 +337,13 @@ </intent-filter> </activity> <service android:name="com.android.gallery3d.app.BatchService" /> <receiver android:name="com.android.camera.DisableCameraReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:name="com.android.camera.MediaSaveService" /> </application> </manifest> src/com/android/camera/DisableCameraReceiver.java 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.camera; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.hardware.Camera.CameraInfo; import android.util.Log; // We want to disable camera-related activities if there is no camera. This // receiver runs when BOOT_COMPLETED intent is received. After running once // this receiver will be disabled, so it will not run again. public class DisableCameraReceiver extends BroadcastReceiver { private static final String TAG = "G:DisableCameraReceiver"; private static final boolean CHECK_BACK_CAMERA_ONLY = true; private static final String ACTIVITIES[] = { "com.android.camera.CameraLauncher", }; @Override public void onReceive(Context context, Intent intent) { // Disable camera-related activities if there is no camera. boolean needCameraActivity = CHECK_BACK_CAMERA_ONLY ? hasBackCamera() : hasCamera(); if (!needCameraActivity) { Log.i(TAG, "disable all camera activities"); for (int i = 0; i < ACTIVITIES.length; i++) { disableComponent(context, ACTIVITIES[i]); } } // Disable this receiver so it won't run again. disableComponent(context, "com.android.camera.DisableCameraReceiver"); } private boolean hasCamera() { int n = android.hardware.Camera.getNumberOfCameras(); Log.i(TAG, "number of camera: " + n); return (n > 0); } private boolean hasBackCamera() { int n = android.hardware.Camera.getNumberOfCameras(); CameraInfo info = new CameraInfo(); for (int i = 0; i < n; i++) { android.hardware.Camera.getCameraInfo(i, info); if (info.facing == CameraInfo.CAMERA_FACING_BACK) { Log.i(TAG, "back camera found: " + i); return true; } } Log.i(TAG, "no back camera"); return false; } private void disableComponent(Context context, String klass) { ComponentName name = new ComponentName(context, klass); PackageManager pm = context.getPackageManager(); // We need the DONT_KILL_APP flag, otherwise we will be killed // immediately because we are in the same app. pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } } src/com/android/gallery3d/util/GalleryUtils.java +1 −3 Original line number Diff line number Diff line Loading @@ -238,9 +238,7 @@ public class GalleryUtils { ComponentName name = new ComponentName(context, CAMERA_LAUNCHER_NAME); int state = pm.getComponentEnabledSetting(name); sCameraAvailableInitialized = true; sCameraAvailable = (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) || (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); sCameraAvailable = (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); return sCameraAvailable; } Loading Loading
AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -337,6 +337,13 @@ </intent-filter> </activity> <service android:name="com.android.gallery3d.app.BatchService" /> <receiver android:name="com.android.camera.DisableCameraReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:name="com.android.camera.MediaSaveService" /> </application> </manifest>
src/com/android/camera/DisableCameraReceiver.java 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.camera; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.hardware.Camera.CameraInfo; import android.util.Log; // We want to disable camera-related activities if there is no camera. This // receiver runs when BOOT_COMPLETED intent is received. After running once // this receiver will be disabled, so it will not run again. public class DisableCameraReceiver extends BroadcastReceiver { private static final String TAG = "G:DisableCameraReceiver"; private static final boolean CHECK_BACK_CAMERA_ONLY = true; private static final String ACTIVITIES[] = { "com.android.camera.CameraLauncher", }; @Override public void onReceive(Context context, Intent intent) { // Disable camera-related activities if there is no camera. boolean needCameraActivity = CHECK_BACK_CAMERA_ONLY ? hasBackCamera() : hasCamera(); if (!needCameraActivity) { Log.i(TAG, "disable all camera activities"); for (int i = 0; i < ACTIVITIES.length; i++) { disableComponent(context, ACTIVITIES[i]); } } // Disable this receiver so it won't run again. disableComponent(context, "com.android.camera.DisableCameraReceiver"); } private boolean hasCamera() { int n = android.hardware.Camera.getNumberOfCameras(); Log.i(TAG, "number of camera: " + n); return (n > 0); } private boolean hasBackCamera() { int n = android.hardware.Camera.getNumberOfCameras(); CameraInfo info = new CameraInfo(); for (int i = 0; i < n; i++) { android.hardware.Camera.getCameraInfo(i, info); if (info.facing == CameraInfo.CAMERA_FACING_BACK) { Log.i(TAG, "back camera found: " + i); return true; } } Log.i(TAG, "no back camera"); return false; } private void disableComponent(Context context, String klass) { ComponentName name = new ComponentName(context, klass); PackageManager pm = context.getPackageManager(); // We need the DONT_KILL_APP flag, otherwise we will be killed // immediately because we are in the same app. pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }
src/com/android/gallery3d/util/GalleryUtils.java +1 −3 Original line number Diff line number Diff line Loading @@ -238,9 +238,7 @@ public class GalleryUtils { ComponentName name = new ComponentName(context, CAMERA_LAUNCHER_NAME); int state = pm.getComponentEnabledSetting(name); sCameraAvailableInitialized = true; sCameraAvailable = (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) || (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); sCameraAvailable = (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); return sCameraAvailable; } Loading