I have a strange issue with the Android camera on Android 13.
My Application has a package name with a length that's greater than 30.
Whatever I do, e.g com.google.mlkit.barcode.Barcode , or creating a surface with androidx.camera, its always the same.Everything works fine until Android 12 and does not work with android 13.
But When I use a Flavour with a shorter package name (30 oder less), it works.
I reported this issue to google, but changing my flavours to shorter ones is not really an option in a productiv running app, does anyone have any idea how to avoid this?
I already updated target ad compiled sdk to 33 and use the newest stable versions of all implementations.
I have the following output in my logcat, if i start a surface on Android 13 with a long package name and the sreec stays just black:
CameraRepository de....Sass.dimadimadimadimadimadima D Added camera: 1
Camera2CameraInfo de....Sass.dimadimadimadimadimadima I Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
CameraValidator de....Sass.dimadimadimadimadimadima D Verifying camera lens facing on SCW_sprout, lensFacingInteger: null
[...]
DeferrableSurface de....Sass.dimadimadimadimadimadima D Surface created[total_surfaces=2, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface#ce8aba5}
DeferrableSurface de....Sass.dimadimadimadimadimadima D Surface created[total_surfaces=3, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface#523af88}
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Use case ImageCapture:androidx.camera.core.ImageCapture-f64980f6-eaa9-435a-819f-8c8db175888e ACTIVE
PreviewView de....Sass.dimadimadimadimadimadima D Surface requested by Preview.
UseCaseAttachState de....Sass.dimadimadimadimadimadima D Active and attached use case: [] for camera: 0
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Use case Preview:androidx.camera.core.Preview-a1671e1e-e37b-4ab4-b0ad-8cd7ee2a695e ACTIVE
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Resetting Capture Session
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Releasing session in state INITIALIZED
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Attempting to force open the camera.
CameraStateRegistry de....Sass.dimadimadimadimadimadima D tryOpenCamera(Camera#b0329a4[id=0]) [Available Cameras: 1, Already Open: false (Previous state: null)] --> SUCCESS
CameraStateRegistry de....Sass.dimadimadimadimadimadima D Recalculating open cameras:
Camera#b0329a4[id=0] OPENING
Camera#49590e[id=1] UNKNOWN
Open count: 1 (Max allowed: 1)
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Opening camera.
Camera2CameraImpl de....Sass.dimadimadimadimadimadima D {Camera#b0329a4[id=0]} Transitioning camera internal state: INITIALIZED --> OPENING
CameraStateMachine de....Sass.dimadimadimadimadimadima D New public camera state CameraState{type=OPENING, error=null} from OPENING and null
CameraStateMachine de....Sass.dimadimadimadimadimadima D Publishing new public camera state CameraState{type=OPENING, error=null}
UseCaseAttachState de....Sass.dimadimadimadimadimadima D All use case: [androidx.camera.core.ImageCapture-f64980f6-eaa9-435a-819f-8c8db175888e89172630, androidx.camera.core.ImageAnalysis-98e2e014-5983-45be-9438-697f6ebd4550206087601, androidx.camera.core.Preview-a1671e1e-e37b-4ab4-b0ad-8cd7ee2a695e2326616] for camera: 0
libc de....Sass.dimadimadimadimadimadima W Access denied finding property "persist.vendor.camera.privapp.list"
CameraService pid-1414 I CameraService::connect call (PID -1 "de.supinfo.FISass.dimadimadimadimadimadima", camera ID 0) and Camera API version 2
CameraService pid-1414 I [hmdcb] CameraService::makeClient call (PID 25019 "de.supinfo.FISass.dimadimadimadimadimadima", camera ID 0) and Camera API version 2, g_isCTS 0, g_isCTS_V 0,
Camera2ClientBase pid-1414 I Camera 0: Opened. Client: de.supinfo.FISass.dimadimadimadimadimadima (PID 25019, UID 10007)
libc de....Sass.dimadimadimadimadimadima W Access denied finding property "vendor.camera.aux.packagelist"
CameraManagerGlobal de....Sass.dimadimadimadimadimadima E Camera 5 is not available. Ignore physical camera status change
libc de....Sass.dimadimadimadimadimadima W Access denied finding property "vendor.camera.aux.packagelist"
libc de.supinfo.FISass.pct W Access denied finding property "vendor.camera.aux.packagelist"`
Related
I am going through the CameraX tutorial at Android Developers https://developer.android.com/codelabs/camerax-getting-started#3 using version 1.1.0 of the library. The logs look good at first, but later a TimeoutException is raised and the camera preview remains black:
(omitted)
D/CameraStateRegistry: Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera#f35a3d7[id=0] OPEN
Camera#e46a673[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
D/CameraStateMachine: New public camera state CameraState{type=OPEN, error=null} from OPEN and null
D/CameraStateMachine: Publishing new public camera state CameraState{type=OPEN, error=null}
D/UseCaseAttachState: All use case: [androidx.camera.core.Preview-c7727ae2-d02c-4135-956c-a76c24deb02d40667318] for camera: 0
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.Preview-c7727ae2-d02c-4135-956c-a76c24deb02d40667318] for camera: 0
D/Camera2CameraImpl: {Camera#f35a3d7[id=0]} Transitioning camera internal state: OPENED --> OPENED
D/CameraStateMachine: New public camera state CameraState{type=OPEN, error=StateError{code=4, cause=java.util.concurrent.TimeoutException: Cannot complete surfaceList within 5000}} from OPEN and StateError{code=4, cause=java.util.concurrent.TimeoutException: Cannot complete surfaceList within 5000}
D/CameraStateMachine: Publishing new public camera state CameraState{type=OPEN, error=StateError{code=4, cause=java.util.concurrent.TimeoutException: Cannot complete surfaceList within 5000}}
My virtual hardware is Pixel 4 API 30, my Samsung A52s behaves in the same way. The code is the same as in the above tutorial, but in Java.
What am I doing wrong?
I am working on a camera app based on the sample CameraX app from Google that can be found on GitHub. Sometimes, when I reopen the app after running in the background, the camera won`t open and the preview screen remains black. When the app is opening the camera, normally the following log is shown:
D/PreviewView: Surface requested by Preview.
D/CameraStateRegistry: Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera#f2ad3fe[id=0] OPENING
Camera#35c320a[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
D/CameraStateRegistry: Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera#f2ad3fe[id=0] OPEN
Camera#35c320a[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
However, when the app does not open, only this log is shown:
Active and attached use case: [] for camera: 0
D/CameraStateRegistry: Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera#f2ad3fe[id=0] OPENING
Camera#35c320a[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
... without the notice that the camera has been opened correctly.
Any idea what is going wrong here and how to fix it?
I am trying to use retrained inception-v3 model in Tensroflow android demo app, no output shown.
What I have done
Trainded the model per description retrain inception. After training (only five classes) I have tested the graph using
bazel build tensorflow/examples/label_image:label_image &&
bazel-bin/tensorflow/examples/label_image/label_image \
--output_layer=final_result \
--labels=/tf_files/retrained_labels.txt \
--image=/home/hannan/Desktop/images.jpg \
--graph=/tf_files/retrained_graph.pb
and following are the outputs
I tensorflow/examples/label_image/main.cc:206] shoes (3): 0.997833
I tensorflow/examples/label_image/main.cc:206] chair (1): 0.00118802
I tensorflow/examples/label_image/main.cc:206] door lock (2): 0.000544737
I tensorflow/examples/label_image/main.cc:206] bench (4): 0.000354453
I tensorflow/examples/label_image/main.cc:206] person (0): 7.93592e-05
Done the optimization for inference using
bazel build tensorflow/python/tools:optimize_for_inference
bazel-bin/tensorflow/python/tools/optimize_for_inference \
--input=/tf_files/retrained_graph.pb \
--output=/tf_files/optimized_graph.pb \
--input_names=Mul \
--output_names=final_result
and tested the output graph again works fine.
finaly ran the following strip_unsued.py
python strip_unused.py \
--input_graph=/tf_files/optimized_graph.pb \
--output_graph=/tf_files/stirpped_graph.pb\
--input_node_names="Mul" \
--output_node_names="final_result" \
--input_binary=true
tested the graph again works fine.
Android app chnages in Classifier Activity
private static final int NUM_CLASSES = 5;
private static final int INPUT_SIZE = 229;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Mul:0";
private static final String OUTPUT_NAME = "final_result:0";
private static final String MODEL_FILE"file:///android_asset/optimized_graph.pb";
private static final String LABEL_FILE = "file:///android_asset/retrained_labels.txt";
Build & Ran the project.
Traceback
D/tensorflow: CameraActivity: onCreate org.tensorflow.demo.ClassifierActivity#adfa77e
W/ResourceType: For resource 0x0103045b, entry index(1115) is beyond type entryCount(1)
W/ResourceType: For resource 0x01030249, entry index(585) is beyond type entryCount(1)
W/ResourceType: For resource 0x01030249, entry index(585) is beyond type entryCount(1)
W/ResourceType: For resource 0x01030248, entry index(584) is beyond type entryCount(1)
W/ResourceType: For resource 0x01030247, entry index(583) is beyond type entryCount(1)
D/PhoneWindowEx: [PWEx][generateLayout] setLGNavigationBarColor : colors=0xff000000
I/PhoneWindow: [setLGNavigationBarColor] color=0x ff000000
D/tensorflow: CameraActivity: onStart org.tensorflow.demo.ClassifierActivity#adfa77e
D/tensorflow: CameraActivity: onResume org.tensorflow.demo.ClassifierActivity#adfa77e
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
D/PhoneWindow: notifyNavigationBarColor, color=0x: ff000000, token: android.view.ViewRootImplAO$WEx#5d35dc4
I/OpenGLRenderer: Initialized EGL, version 1.4
I/CameraManagerGlobal: Connecting to camera service
I/tensorflow: CameraConnectionFragment: Adding size: 1920x1440
I/tensorflow: CameraConnectionFragment: Adding size: 1920x1088
I/tensorflow: CameraConnectionFragment: Adding size: 1920x1080
I/tensorflow: CameraConnectionFragment: Adding size: 1280x720
I/tensorflow: CameraConnectionFragment: Adding size: 960x720
I/tensorflow: CameraConnectionFragment: Adding size: 960x540
I/tensorflow: CameraConnectionFragment: Adding size: 800x600
I/tensorflow: CameraConnectionFragment: Adding size: 864x480
I/tensorflow: CameraConnectionFragment: Adding size: 800x480
I/tensorflow: CameraConnectionFragment: Adding size: 720x480
I/tensorflow: CameraConnectionFragment: Adding size: 640x480
I/tensorflow: CameraConnectionFragment: Adding size: 480x368
I/tensorflow: CameraConnectionFragment: Adding size: 480x320
I/tensorflow: CameraConnectionFragment: Not adding size: 352x288
I/tensorflow: CameraConnectionFragment: Not adding size: 320x240
I/tensorflow: CameraConnectionFragment: Not adding size: 176x144
I/tensorflow: CameraConnectionFragment: Chosen size: 480x320
I/TensorFlowImageClassifier: Reading labels from: retrained_labels.txt
I/TensorFlowImageClassifier: Read 5, 5 specified
I/native: tensorflow_inference_jni.cc:97 Native TF methods loaded.
I/TensorFlowInferenceInterface: Native methods already loaded.
I/native: tensorflow_inference_jni.cc:85 Creating new session variables for 7e135ad551738da4
I/native: tensorflow_inference_jni.cc:113 Loading Tensorflow.
I/native: tensorflow_inference_jni.cc:120 Session created.
I/native: tensorflow_inference_jni.cc:126 Acquired AssetManager.
I/native: tensorflow_inference_jni.cc:128 Reading file to proto: file:///android_asset/optimized_graph.pb
I/native: tensorflow_inference_jni.cc:132 GraphDef loaded from file:///android_asset/optimized_graph.pb with 515 nodes.
I/native: stat_summarizer.cc:38 StatSummarizer found 515 nodes
I/native: tensorflow_inference_jni.cc:139 Creating TensorFlow graph from GraphDef.
I/native: tensorflow_inference_jni.cc:151 Initialization done in 931.7ms
I/tensorflow: ClassifierActivity: Sensor orientation: 90, Screen orientation: 0
I/tensorflow: ClassifierActivity: Initializing at size 480x320
I/CameraManager: Using legacy camera HAL.
I/tensorflow: CameraConnectionFragment: Opening camera preview: 480x320
I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
I/RequestThread-0: Configure outputs: 2 surfaces configured.
D/Camera: app passed NULL surface
I/[MALI][Gralloc]: dlopen libsec_mem.so fail
I/Choreographer: Skipped 89 frames! The application may be doing too much work on its main thread.
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#a9290d7 time:114073819
I/CameraDeviceState: Legacy camera service transitioning to state IDLE
I/RequestQueue: Repeating capture request set.
W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
W/LegacyRequestMapper: Only received metering rectangles with weight 0.
W/LegacyRequestMapper: Only received metering rectangles with weight 0.
E/Camera: Unknown message type -2147483648
I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
I/[MALI][Gralloc]: lock_ycbcr: videobuffer_status is invalid, use default value
I/[MALI][Gralloc]: lock_ycbcr: videobuffer_status is invalid, use default value
D/tensorflow: CameraActivity: Initializing buffer 0 at size 153600
D/tensorflow: CameraActivity: Initializing buffer 1 at size 38400
D/tensorflow: CameraActivity: Initializing buffer 2 at size 38400
I/[MALI][Gralloc]: lock_ycbcr: videobuffer_status is invalid, use default value
I/[MALI][Gralloc]: lock_ycbcr: videobuffer_status is invalid, use default value
When I use the app to identify an object no output is shown. Output
this one is also show in logs
I/native: tensorflow_inference_jni.cc:228 End computing. Ran in 4639ms (4639ms avg over 1 runs)
E/native: tensorflow_inference_jni.cc:233 Error during inference: Invalid argument: computed output size would be negative
[[Node: pool_3 = AvgPool[T=DT_FLOAT, data_format="NHWC", ksize=[1, 8, 8, 1], padding="VALID", strides=[1, 1, 1, 1], _device="/job:localhost/replica:0/task:0/cpu:0"](mixed_10/join)]]
E/native: tensorflow_inference_jni.cc:170 Output [final_result] not found, aborting!
I/[MALI][Gralloc]: lock_ycbcr: videobuffer_status is invalid, use default value
I have figured it out.There is typo mistake in ClassifierActivity.
private static final int INPUT_SIZE = 229;
should be
private static final int INPUT_SIZE = 299;
Has anyone see this in the logs, once the app loads the following fires off until you close the app, preventing it from sleeping. (Only attached a small clip but it just keeps repeating this until you close the app.)
11710 D Camera-JNI Using callback buffer from queue of length 3
11633 - I CameraFramework handleMessage: 16
11633 - D Camera-JNI Adding callback buffer to queue, 3 total
11658 I BufferQueueProducer [unnamed-11633-0](this:0xef0c7c00,id:0,api:4,p:290,c:11633) queueBuffer: slot 6 is dropped, handle=0xd67aa660
11633 11710 D Camera-JNI Using callback buffer from queue of length 3
11633 - I CameraFramework handleMessage: 16
11633 - D Camera-JNI Adding callback buffer to queue, 3 total
11633 11658 I BufferQueueProducer [unnamed-11633-0](this:0xef0c7c00,id:0,api:4,p:290,c:11633) queueBuffer: slot 0 is dropped, handle=0xdbc50d80
11633 11710 D Camera-JNI Using callback buffer from queue of length 3
11633 - I CameraFramework handleMessage: 16
11633 - D Camera-JNI Adding callback buffer to queue, 3 total
Using Cordova version 6.2.0 with Cordova android version 5.1.1
Happens with or without the use of plugins.
The only way I have found to stop it is to not include the android camera permission.
Following the "Five minute quick start" documentation for uploading a file from an Android device to Google Drive, I've written a test application that successfully uploads a file but my attempt at copying the relevant code to a larger application doesn't upload a file because its Google Account Picker is always getting canceled:
the onActivityResult() result code is 0 (i.e.,
RESULT_CANCELED),
the onActivityResult() intent argument is null, and
the logcat (shown below) reveals that "Activity is launching as a new task, so
cancelling activity result."
04-22 02:04:25.098: D/alsa_ucm(162): snd_use_case_set(): uc_mgr 0x40e59388 identifier _verb value HiFi Lowlatency
04-22 02:04:25.098: D/alsa_ucm(162): Set mixer controls for Speaker enable 1
04-22 02:04:25.098: D/ACDB-LOADER(162): ACDB -> send_afe_cal
04-22 02:04:25.098: I/ActivityManager(526): START u0 {act=com.google.android.gms.common.account.CHOOSE_ACCOUNT cmp=com.google.android.gms/.common.account.AccountPickerActivity (has extras)} from pid 3484
04-22 02:04:25.098: W/ActivityManager(526): Activity is launching as a new task, so cancelling activity result.
04-22 02:04:25.108: D/alsa_ucm(162): Set mixer controls for HiFi Lowlatency enable 1
04-22 02:04:25.108: D/ALSAModule(162): Device value returned is hw:0,14
04-22 02:04:25.118: D/ALSAModule(162): setHardwareParams: reqBuffSize 1024 channels 2 sampleRate 48000
04-22 02:04:25.118: D/ALSAModule(162): setHardwareParams: buffer_size 2048, period_size 1024, period_cnt 2
04-22 02:04:25.188: D/dalvikvm(526): GC_FOR_ALLOC freed 565K, 15% free 18562K/21684K, paused 71ms, total 71ms
04-22 02:04:25.248: D/overlay(159): Unset pipe=VG0 dpy=0; Unset pipe=VG1 dpy=0; Unset pipe=RGB1 dpy=0
04-22 02:04:25.248: W/InputMethodManagerService(526): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#41ebd7e0 attribute=null, token = android.os.BinderProxy#42018140
04-22 02:04:27.991: D/dalvikvm(526): GC_FOR_ALLOC freed 422K, 15% free 18564K/21684K, paused 65ms, total 66ms
04-22 02:04:28.011: I/ActivityManager(526): No longer want com.google.android.marvin.talkback (pid 5301): empty #17
04-22 02:04:28.241: D/overlay(159): Set pipe=RGB1 dpy=0; Set pipe=VG0 dpy=0; Set pipe=VG1 dpy=0;
04-22 02:04:28.672: D/overlay(159): Unset pipe=VG0 dpy=0; Unset pipe=VG1 dpy=0; Unset pipe=RGB1 dpy=0;
The code that launches the Google Account Picker is exactly the same in both applications but the picker gets canceled only in the larger application.
// Handle item selection
case R.id.action_select_account:
mCredential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
Intent intent2 = mCredential.newChooseAccountIntent();
showToast("intent extra: " + intent2.getStringExtra(AccountManager.KEY_ACCOUNT_NAME)); // TODO: remove after test
startActivityForResult(intent2, REQUEST_ACCOUNT_PICKER);
return true;
default:
return false;
The test application and the larger application are both debug versions, including the same jars (shown below), and running on the same device (Nexus 4, OS 4.2.2) but, as suggested in the five minute quickstart, each application has its own client ID generated by Google APIs Console.
The result of this cancellation is that the onActivityResult() runs as soon as the Google Account Picker gets drawn, well before an account is selected.
UPDATE:
After an approximately equal amount of trial and error, it turns out that removing the following from AndroidManifest.xml fixed the problem.
android:launchMode="singleInstance"
My initial question of why now shifts to why does the Google Account Picker in Android need to create multiple instances?
Thanks,
Greg
If you use singleInstance you permit no other activities to be part of its task. Use singleTask instead.
As stated on http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
a few paragraphs down.
The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.
As described in the question's update, the account picker started working when I removed singleInstance launchMode from AndroidManifest.xml. I don't know if this single instance launch mode behavior is a bug or a lack of documentation, but I submitted it to the Android Issue Tracker: issue 54656
For some reason, the intent returned by account manager has singleTop set, which always causes your onActivityResult to fail immediately and return a 0 resultCode (Activity.RESULT_CANCELLED) or whatever. I had to zero-out the intent flags to prevent this
// prevent running AccountPicker as SingleTop which fails and calls onActivityResult immediately otherwise
intent.setFlags(0);
startActivityForResult(intent, AccountManagerUtils.GOOGLE_AUTH_REQUEST_CODE);