Your app contains an Implicit Internal Intent vulnerability - java

Google rejecting my app and i'm having trouble with this security error that appear when i submit app as production release:
Implicit Internal Intent
Your app contains an Implicit Internal Intent vulnerability. Please
see this Google Help Center article for details.
com.mypackage.name.sync.SyncService.onHandleIntent
I applied all recommendations listed here:
Remediation for Implicit PendingIntent Vulnerability
But the error still persists.
My service:
public class SyncService extends IntentService {
protected void onHandleIntent(Intent intent) {
...
Intent i = new Intent("com.mypackage.name.REFRESH");
app.sendBroadcast(i);
...
}
}
Manifest:
<service
android:name=".sync.SyncService"
android:exported="false" >
</service>
The service started in many places in 3 methods like this:
(As recommended by google i did add PendingIntent.FLAG_IMMUTABLE)
Method 1:
Intent intent = new Intent(this, SyncService.class);
PendingIntent pIntent = PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmMgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis,
SYNC_FREQUENCY, pIntent);
Method 2:
Intent intent = new Intent("com.mypackage.name.REFRESH");
intent = new Intent(getApplicationContext(), SyncService.class);
intent.putExtra("notification_unassigned_sync", true);
startService(intent);
Method 3:
Intent intent = new Intent(getApplicationContext(), SyncService.class);
startService(intent);
Is there anything wrong in my code ? Any recommendations ?

Setting the package name for the intents should fix the issue
intent.setPackage("com.mypackage.name"); // replace with your package name
// from AndroidManifest.xml

How to implement broadcast receiver?
Create a java class named MyBroadcastReceiver.java.
Paste this code in the class
public class MyBroadcastReceiverextends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"I have received.",Toast.LENGHT_SHORT).show();
}
}
Once you have implemented this code, you need to add this to you manifest inside the application tag.
<receiver android:name="com.chatverse.free.TimeBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.mypackage.name.REFRESH"/>
</intent-filter>
</receiver>
Add this code to your activity which opens the first.
IntentFilter mFilter = new IntentFilter("com.mypackage.name.REFRESH");
registerReceiver(new MyBroadcastReceiver(), mFilter);

Related

Broadcast receiver. I want to move to another activity through a broadcast receiver after the charger is disconnected

I'm making a university project where I have to make a charger alarm. I select a ringtone, enter a pin, then plug in a charger. When I plug out, it moves to another activity where the phone starts ringing, the screen is locked and can only proceed if provided a correct pin code.
I'm stuck at the point where I have to move from one activity to another when the charger disconnects.
My code is not working. This is the receiver in the manifest file:
<receiver android:name=".MainActivity$PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
This is the broadcast receiver I made in the MainActivity:
public class PowerConnectionReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Toast.makeText(context, "The device is not charging", Toast.LENGTH_SHORT).show();
Intent myintent = new Intent(MainActivity.this,setter.class);
startActivity(myintent);
}
}
Please see:
You cannot receive this through components declared in manifests, only
by explicitly registering for it with...
https://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED
And did you set the corresponding permission?
<uses-permission android:name="android.permission.BATTERY_STATS"/>
Your intent has not correct parameters.
Intent myintent = new Intent(MainActivity.this,setter.class);
Change should be:
Intent myintent = new Intent(context, MainActivity.class)
Make sure your <receiver></receiver> tags are out of the activity tag in Manifest. Place them in application level.

Close APK installer dialog

I work on an enterprise app with a custom update (w/o Google Play). I download and run the update directly from the APK:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
It brings me the installer dialog. After installing the update I relaunch my app with a broadcast receiver:
<receiver android:name=".content.SilentUpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
public class SilentUpdateReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
The app opens in the foreground, but the installer dialog remains to stay in the background.
How to close this dialog programmatically?

BroadcastReceiver.onReceive not called, but Activity.onNewIntent do. Why?

I am trying to get "DeleteIntent" callback from my notification.
BroadcastReceiver.onReceive not called from PendengIntent, while it works OK when broadcast is launched manually with sendBroadcast(deleteIntent).
It works well when intent target is Activity (hits Activity.onNewIntent) but it is weird to use it since activity goes foreground when message dismissed.
Please, help to get onReceive call to BroadcastReceiver.
It is visible, exported and enabled, located in the same package.
MyCancelReceiver class
public class MyCancelReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
}
}
Android manifest
<activity android:name=".MainActivity" android:launchMode="singleTask">
<MyCancelReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="notification_cancelled"/>
</intent-filter>
</receiver>
MainActivity
private MyCancelReceiver mReceiver;
#Override
public void onStart() {
super.onStart();
IntentFilter filter = new IntentFilter();
filter.addAction("notification_cancelled");
mReceiver = new MyCancelReceiver();
registerReceiver(mReceiver, filter);
}
#Override
public void onStop() {
super.onStop();
unregisterReceiver(mReceiver);
}
Notification creation:
Intent cancelIntent = new Intent(getApplicationContext(), MyCancelReceiver.class);
cancelIntent.setAction("notification_cancelled");
cancelIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent deleteIntent = PendingIntent.getActivity(getApplicationContext(), 0, cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification not = new Notification.Builder(getApplicationContext(), Util.ANDROID_CHANNEL_ID)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setSmallIcon(R.drawable.default)
.setAutoCancel(true)
.setDeleteIntent(deleteIntent)
.setContentIntent(contentIntent)
.build();
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, not);
Thank you in advance.
It's because when you start your activity, onStart() gets called and you will get a callback in onReceive() as soon as the activity is launched. But when you click your notification onStart won't be called as the activity is already created, In this case, onStart wont be called. Try registering in onResume(), I am pretty sure it will work.
Problem solved using an answer from this thread Click on android notification icon does not trigger broadcast receiver
Explicit intent replaced with implicit one.
Intent cancelIntent = new Intent("notification_canceled");

AlarmManager doesn't do anything

I'm trying to make an Alarm using the Alarm Manager. The app runs without any error messages, but nothing happens.
I tried solutions from developer.android.com and suggestions from stackoverflow.
I also tried copying a complete tutorial i found, but nothing worked.
The app runs on API22 and was tested on an emulator(API23) and a real device(API22).
This is my Code:
MainActivity.java startAlarm():
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(MainActivity.this,AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,myIntent,0);
manager.set(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime()+3000,pendingIntent);
AlarmReceiver.java:
public class AlarmReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"THIS IS MY ALARM",Toast.LENGTH_LONG).show();
}
}
AndroidManifest.xml, between <manifest...> and </manifest>:
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver>
your reciever name is AlarmToastReceiver not AlarmReceiver
try:
<receiver android:process=":remote" android:name=".AlarmToastReceiver "></receiver>

AlarmManager/BroadcastReceiver not working

I've been trying to setup my first alarm using AlarmManager and BroadCastReceiver as explained here: http://smartandroidians.blogspot.com.es/2010/04/alarmmanager-and-notification-in.html
My setup:
AndroidManifest.xml:
<receiver android:name="es.radiopodcastellano.player.SleepAlarm" />
My main Activity onCreate (this code actually resides on a subclass, but to simplify I put it there):
#Override
public void onCreate(Bundle savedInstanceState) {
// <Stripped code>
AlarmManager alarm = (AlarmManager) currentContext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), SleepAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarm.set(AlarmManager.RTC_WAKEUP,(System.currentTimeMillis() + (5 * 1000)),pendingIntent);
}
SleepAlarm.java:
public class SleepAlarm extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("RPod_SleepAlarm","Alarm!!");
}
}
Output from "adb shell dumpsys alarm" show this, so it seems the intent is being called:
es.radiopodcastellano.player
221ms running, 32 wakeups
44 alarms: flg=0x4 cmp=es.radiopodcastellano.player/.SleepAlarm
However, Logcat shows nothing for "RPod_SleepAlarm" tag. What could I be doing wrong?
I found the problem.
The receiver on the manifest was inside another receiver for a widget, and it must be a children of the application. So, if you're having the same behaviour as me, please check that you've set up the AndroidManifest.xml correctly:

Categories