MediaProjectionManager.getMediaProjection( ) problem in android 12 - android

I create a screenshot application and that work good in all of the android devices.
But I have a problem with take screenshot in android 12 (Xiaomi 11t) I'm using static intent and result code and then clone intent and pass it to this function mediaProjectionManager.getMediaProjection(resultCode,clonedIntent) I have no problem with take screen shot for first time but I can't take screen shot for second time and I get this error.
if you need more info please tell me.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.koala.classor, PID: 10824
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.Set.add(java.lang.Object)' on a null object reference
at android.os.Parcel.createExceptionOrNull(Parcel.java:2431)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:235)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:59)
at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:119)
at com.koala.classor.G.getMediaProjection(G.java:86)
at com.koala.classor.OverScreenWindowService$2$1.run(OverScreenWindowService.java:194)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8105)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:553)
at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:137)
at android.os.Binder.execTransactInternal(Binder.java:1182)
at android.os.Binder.execTransact(Binder.java:1146)

MIUI13+Android12
The RemoteException error is reported on line 553 of MediaProjectionManagerService. After checking the source code, the error message is that the package for applying for mediaprojection cannot be found.
It is guessed that MIUI maintains a separate list for this, only the package that has applied for permission will be in it, and it will be removed after obtaining and closing mediaprojection. No such mechanism has been seen in other systems.
In other words, intent data cannot be reused. The solution is also very simple, just don’t close the mediaprojection after using it.

Related

Detect added libraries to pirated Android app?

It appears from my crash reports that some people pirate my app and add advertisements to monetise it.
The stack trace from the crash report seems to show a bunch of calls to a library to show interstitials?
Is it possible for me to add code to detect the presence of the com.test.ylh or com.qq.e library?
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#da2c866 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1126)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:439)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at android.app.Dialog.show(Dialog.java:473)
at com.qq.e.comm.plugin.intersitial2.e.a(A:315)
at com.qq.e.comm.plugin.intersitial2.e.show(A:113)
at com.qq.e.comm.plugin.intersitial2.e.show(A:107)
at com.qq.e.comm.plugin.intersitial2.d.show(A:35)
at com.qq.e.ads.interstitial2.UnifiedInterstitialAD.show(Unknown Source:4)
at com.test.ylh.InterAd$2.run(InterAd.java:53)
at android.app.Activity.runOnUiThread(Activity.java:6972)
at com.test.ylh.InterAd.showAd(InterAd.java:50)
at com.test.ylh.InterAd.onADReceive(InterAd.java:108)
at com.qq.e.comm.plugin.intersitial2.a$1.run(A:169)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7860)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
You can check if a class exists with a method as described over here: How to check if class exists somewhere in package?
However, they could also remove that check when recompiling the app. So it won't be airtight. You can make it more difficult for the "pirates" by adding proper code obfuscation: https://developer.android.com/studio/build/shrink-code#obfuscate

Android RemoteServiceException: Bad notification posted from package Couldn't cache contentViews

I have an Android app that is crashing due to an unhandled exeption, but only on one particular device (running Nougat). I believe they are the only one of my testers that is running Nougat. This is the exception:
Java.Lang.RuntimeException: Bad notification posted from package [my
package name]: Couldn't cache contentViews: package=[my package name]
Here is the stack trace:
android.app.RemoteServiceException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1675)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Xamarin caused by: Java.Lang.RuntimeException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
--- End of managed Java.Lang.RuntimeException stack trace ---
android.app.RemoteServiceException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1675)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
The stack trace does not show any of my own code. My app does not create any notifications itself, but it does use an open source package (Xamarin Media Manager) that does. The stack trace does not show any of that package's code either.
So, I'm not sure where to look. I have tried searching for this exception, and although I get a couple of hits for "Bad notification posted", none of them seem to address my issue. I do not get ANY hits for "Couldn't cache contentViews".
If it helps, here is the code (as best I can tell) from the package that creates the notification: (note this is c# code, because it's using Xamarin/Mono)
/// <summary>
/// When we start on the foreground we will present a notification to the user
/// When they press the notification it will take them to the main page so they can control the music
/// </summary>
public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
{
var icon = (_appliactionContext.Resources?.GetIdentifier("xam_mediamanager_notify_ic", "drawable", _appliactionContext?.PackageName)).GetValueOrDefault(0);
_notificationStyle.SetMediaSession(_sessionToken);
_notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);
_builder = new NotificationCompat.Builder(_appliactionContext)
{
MStyle = _notificationStyle
};
_builder.SetSmallIcon(icon != 0 ? icon : _appliactionContext.ApplicationInfo.Icon);
_builder.SetContentIntent(_pendingIntent);
_builder.SetOngoing(mediaIsPlaying);
_builder.SetVisibility(1);
SetMetadata(mediaFile);
AddActionButtons(mediaIsPlaying);
if (_builder.MActions.Count >= 3)
((NotificationCompat.MediaStyle)(_builder.MStyle)).SetShowActionsInCompactView(0, 1, 2);
NotificationManagerCompat.From(_appliactionContext)
.Notify(MediaServiceBase.NotificationId, _builder.Build());
}

Stock Android : NPException : at android.content.res.StringBlock.get(int)

SO users, please read fully then decide to mark the Duplicate for NullPointer exception.
While app launch, from ApplicationExt(extends Application), we initialize the thread in which load the CSV file from Resource bundle(RawSource). It always works on many of the devices. But get crashed on below device for the very first time. For the second time, it gets loaded from the bundle.
OS version : Lollipop (5.1.1)
Device : OnePlus A0001
Crash Log:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference
at android.content.res.AssetManager.getResourceValue(AssetManager.java:213)
at android.content.res.Resources.getValue(Resources.java:1334)
at android.content.res.Resources.getValue(Resources.java:1323)
at android.content.res.Resources.openRawResource(Resources.java:1242)
at android.content.res.Resources.openRawResource(Resources.java:1219)
at com.xxxx.yyyy.network.NetworkManager.getBrandCodesFromCsvFile(NetworkManager.java:2961)
at com.xxxx.yyyy.network.NetworkManager.getBrandCodes(NetworkManager.java:3221)
at com.xxxx.yyyy.network.NetworkManager.checkAndUpdateMobileCodeFromBundle(NetworkManager.java:3110)
at com.xxxx.yyyy.OurApplication$1.run(OurApplication.java:132)
at java.lang.Thread.run(Thread.java:818)
Code Snippet:
In Application, onCreate(...),
Create a thread with code of csv load
Run the thread at the end of onCreate -> new Thread(ourThread).start();
Exact crash on this line :
InputStream bundleStream = OurApplicationClass.getContext().getResources().openRawResource(sourceId);
Note:
I've found related issue on Github. https://github.com/osmandapp/Osmand/issues/2575. But unable to confirm whether it's working for my case.

Codename one crash during capture audio

I'm getting a crash on our app on a part that used to work:
a call to Capture.captureAudio() to get the path to a newly recorded audio file.
I've tested on android and I get this stack trace:
[EDT] 0:5:30,336 - Exception: java.lang.NullPointerException - Attempt to invoke interface method 'int android.database.Cursor.getColumnIndexOrThrow(java.lang.String)' on a null object reference
java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getColumnIndexOrThrow(java.lang.String)' on a null object reference
at com.codename1.impl.android.AndroidImplementation.convertImageUriToFilePath(AndroidImplementation.java:5197)
at com.codename1.impl.android.AndroidImplementation.onActivityResult(AndroidImplementation.java:4936)
at com.codename1.impl.android.CodenameOneActivity$9.run(CodenameOneActivity.java:506)
at com.codename1.ui.Display.processSerialCalls(Display.java:1150)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1094)
at com.codename1.ui.Display.invokeAndBlock(Display.java:1204)
at com.codename1.ui.Display.invokeAndBlock(Display.java:1242)
at com.codename1.capture.Capture.captureAudio(Capture.java:95)
at com.handover.app.taskhandlers.AudioTaskListener$AudioShowHandler.lambda$run$11(AudioTaskListener.java:86)
at com.handover.app.taskhandlers.AudioTaskListener$AudioShowHandler.access$lambda$0(AudioTaskListener.java)
at com.handover.app.taskhandlers.AudioTaskListener$AudioShowHandler$$Lambda$1.actionPerformed(Unknown Source)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:459)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:362)
at com.codename1.ui.Button.fireActionEvent(Button.java:411)
at com.codename1.ui.Button.released(Button.java:442)
at com.codename1.ui.Button.pointerReleased(Button.java:530)
at com.codename1.ui.Form.pointerReleased(Form.java:2613)
at com.codename1.ui.Form.pointerReleased(Form.java:2549)
at com.codename1.ui.Component.pointerReleased(Component.java:3147)
at com.codename1.ui.Display.handleEvent(Display.java:2024)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1066)
at com.codename1.ui.Display.invokeAndBlock(Display.java:1204)
at com.codename1.ui.Display.invokeAndBlock(Display.java:1242)
at com.codename1.ui.AnimationManager.addAnimationAndBlock(AnimationManager.java:105)
at com.codename1.ui.Container.animateHierarchy(Container.java:2465)
at com.codename1.ui.Container.animateHierarchyAndWait(Container.java:2185)
at com.handover.app.ui.components.ToastNotification.setVisible(ToastNotification.java:782)
at com.handover.app.ui.components.ToastNotification.updateStatus(ToastNotification.java:530)
at com.handover.app.ui.components.ToastNotification.removeStatus(ToastNotification.java:738)
at com.handover.app.ui.components.ToastNotification.access$700(ToastNotification.java:82)
at com.handover.app.ui.components.ToastNotification$Status.clear(ToastNotification.java:380)
at com.handover.app.ui.components.NetworkProgressIndicator.actionPerformed(NetworkProgressIndicator.java:55)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:459)
at com.codename1.ui.util.EventDispatcher.access$100(EventDispatcher.java:45)
at com.codename1.ui.util.EventDispatcher$CallbackClass.run(EventDispatcher.java:95)
at com.codename1.ui.Display.processSerialCalls(Display.java:1150)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1094)
at com.codename1.ui.Display.mainEDTLoop(Display.java:995)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:831)
It has been a while since this part of the app was throughly tested, and I'm not entirly sure which version of CN1 this was working on.
Capture.capturePhoto() and Capture.captureVideo() are both still working as expected.
This should be fixed in current versions of the Android build

java.lang.NoSuchMethodError: android.app.ANRAppManager.dumpMessageHistory

My Android App reported some crash report:
java.lang.NoSuchMethodError: android.app.ANRAppManager.dumpMessageHistory
at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1177)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:609)
at android.os.Binder.execTransact(Binder.java:351)
at dalvik.system.NativeStart.run(Native Method)
A lot of android device reported the same crash:
Android|Android=>3
android|Coolpad=>1
Android|Lenovo=>1
Android|VIVO=>2
apsl|Lenovo=>1
apsl|Samsung=>2
ARES|AE912=>3
Coolpad|Coolpad=>2
COWW|C920=>5
GoDonie|GoDonie F7=>1
HESM|HSEM TD777=>2
HMI|H2=>1
huawei|huawei=>2
intki|intki_E86=>3
ioco|i9100 X6=>1
Lenovo|Lenovo A820T=>1
MEEG|MEEG_101M=>2
NEWLAND|N003=>2
SAST|SAST YC500=>1
But I didn't find "dumpMessageHistory" in my code, please help, thanks!!
The class android.app.ANRAppManager can not be found in Android Application Framework (/frameworks/base/core/java/android/app). Probably it is a vendor supplied class for MTK chips. Whenever there is an ANR raised, ANRAppManager.dumpMessageHistory would be invoked.
The best advice would be to keep track of all cases of ANR that takes place in your app and try to fix it.

Categories

Resources