标签: android-binder

Android OS中有哪些IPC机制?

请问任何人请告诉我android中存在的所有IPC机制是什么.

据我所知:

1)意图,
2)粘合剂.

android ipc android-intent android-bundle android-binder

61
推荐指数
5
解决办法
7万
查看次数

为什么NotificationManagerCompat :: cancelAll()获取SecurityException?

使用NotificationManagerCompat取消所有通知.

NotificationManagerCompat manager =  
    NotificationManagerCompat.from(ctx.getApplicationContext());
manager.cancelAll();
Run Code Online (Sandbox Code Playgroud)

它有一段时间异常(大部分时间都有效).

在Andoid 6上:

java.lang.SecurityException:Permission Denial:来自pid = 22994的getCurrentUser(),uid = 10184需要android.permission.INTERACT_ACROSS_USERS

Fatal Exception: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=22994, uid=10184 requires android.permission.INTERACT_ACROSS_USERS
   at android.os.Parcel.readException(Parcel.java:1602)
   at android.os.Parcel.readException(Parcel.java:1555)
   at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:649)
   at android.app.NotificationManager.cancelAll(NotificationManager.java:323)
   at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)
Run Code Online (Sandbox Code Playgroud)

在Android 5.0,4.4.2上:

ava.lang.SecurityException:权限拒绝:来自pid = 5460的getIntentSender(),uid = 10135,(需要uid = 1000)不允许在android.os.Parcel.readException(Parcel.java:1465)中作为包android发送

Fatal Exception: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=3109, uid=10153, (need uid=1000) is not allowed to send as package android
   at android.os.Parcel.readException(Parcel.java:1472)
   at android.os.Parcel.readException(Parcel.java:1426)
   at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:271)
   at android.app.NotificationManager.cancelAll(NotificationManager.java:220)
   at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 可能是什么原因?
  2. 这里有什么身份证?难道ctx.getApplicationContext().getApplicationInfo().uid …

android android-notifications android-securityexception android-binder

27
推荐指数
2
解决办法
2379
查看次数

什么是强指针和弱指针

我对"强指针"和"弱指针"的概念感到困惑.Diane Hackborn自己说:

当有强大的指针时,物体将保持在周围; 一旦最后一个被释放它就会被销毁.使用弱指针可以做的就是比较并试图提升为强指针; 如果对象上没有其他强指针,后者将失败.

这对我来说还不太清楚.强指针是否等同于a(boost::)共享指针?弱指针的作用是什么,只是为了试图将自己推向强指针?比如,我们什么时候需要弱点和强点?

更新:

谢谢大家,但我专门询问有关Android的内核spwp,和他们无关,在所有的Java引用.

基本上我试图破解这里的代码http://www.androidenea.com/2010/03/share-memory-using-ashmem-and-binder-in.html 并不真正理解使用spwp

更新:

实际答案在于接受答案的评论.感谢Gabe Sechan:

强指针和弱指针是不同的智能指针实现,并且做同样的事情 - 当指针超出范围时,只要至少一个强指针引用它,它就不会被释放.如果只有弱指针(或没有)引用它.每当对其进行强或弱引用时,都会进行检查.

如果我有10个弱引用引用相同的对象,并且其中一个超出范围,该对象将被销毁?虽然有强指针,但只有当它们全部10个超出范围时才会销毁对象?

是的,差不多.如果你只有10个弱指针,当最后一个强指针超出范围时,它可能已经超出了范围.如果有剩余内存,实现可能会允许它延长一点时间,但如果你进入低内存条件它将被切断,并且听起来不像它的实现是从她的引用提前.并且使用它仍然主要是缓存 - 它大致相当于boost shared_ptr和boost weak_ptr.所以基本上,弱指针可以让它引用的对象随时消失.

c android-source android-binder

26
推荐指数
2
解决办法
2万
查看次数

Android java binder FAILED BINDER TRANSACTION?

我正在尝试从服务中下载图像并将其显示在活动中,但我一直在努力

 java binder FAILED BINDER TRANSACTION
Run Code Online (Sandbox Code Playgroud)

这是我的服务代码

public class DownloadImageService extends Service {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    new LoadImageAsync().execute(intent.getStringExtra("type"));
    return Service.START_NOT_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

private class LoadImageAsync extends AsyncTask<String, Void, String> {
    byte[] compressedImage;
    Bitmap bmp;
    String img;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... params) {

        try {
            URL url = new URL(imgUrl);
            bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
            compressedImage = CompressBitmap.compresssImage(bmp);
            img = Base64.encodeToString(compressedImage, …
Run Code Online (Sandbox Code Playgroud)

android android-binder

17
推荐指数
2
解决办法
3万
查看次数

远程服务拒绝对绑定的权限

我有一个远程服务,外部应用程序可以绑定到该服务.在某些情况下,我可能希望拒绝绑定.根据文件,

将通信通道返回给服务.如果客户端无法绑定到服务,则可能返回null.

@Override
public IBinder onBind(final Intent intent) {
    return null;
}
Run Code Online (Sandbox Code Playgroud)

返回null确实不会返回IBinder对象,因此会阻止连接,但是调用应用程序无法正确接收此"信息".

boolean bound = context.bindService(intent, serviceConnection, flagsHere);
Run Code Online (Sandbox Code Playgroud)

无论是否从服务返回null,这总是返回true?

根据文件,

返回 - 如果已成功绑定到服务,则返回true; 如果未建立连接,则返回false,因此您将不会收到服务对象

我曾假设从onBind返回null 会导致bindService返回false.假设永远不是一个好主意......

但是,返回null确实会阻止ServiceConnection实例化调用,但是这样做的结果就是没有选项来检查绑定在onServiceConnected中是否实际为null .

所以,我的问题 - 如果绑定请求被拒绝,应用程序如何"知道"?

另外,如果我在飞行中决定对onRebind(先前从onUnbind返回true )的请求应该被拒绝,我似乎无法覆盖行为以防止这种情况:

@Override
public void onRebind(final Intent intent) {

    if (shouldAllowRebind(intent)) {
        super.onRebind(intent);
    } else {
        // ?
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望有人可以为我解释一下.提前致谢.

java android android-service android-binder

17
推荐指数
1
解决办法
1101
查看次数

Android绑定安全性

Binder在Android中提供的进程间通信是否在中间攻击中受到保护?有没有提供此信息的文档?

security android android-binder

16
推荐指数
2
解决办法
4112
查看次数

在Android中使用Binder for IPC的优点

在Android堆栈中使用Binder for IPC(Semaphores,Message Queue,PIPES)有什么好处?

android android-binder

16
推荐指数
3
解决办法
7427
查看次数

使用Android原生Binder发送自定义对象

我只能找到有关Parcelable的Java示例.我的目标是在本机C++(而不是NDK)中创建一个简单的服务和客户端,它将使用Binder来接收和发送序列化的自定义对象.

MyClass
+ std::string
+ enum
+ int
+ bool
Run Code Online (Sandbox Code Playgroud)

c++ java-native-interface android android-ndk android-binder

15
推荐指数
1
解决办法
660
查看次数

什么是Android Binder"交易?"

我在TransactionTooLargeException从单个APK运行的两个Android进程之间发送消息时收到了消息.每条消息只包含少量数据,远小于总计1 mb(如文档中所指定).

我创建了一个测试应用程序(下面的代码)来解决这个问题,并注意到三件事:

  1. android.os.TransactionTooLargeException如果每条消息都超过200 kb 我得到了一个.

  2. android.os.DeadObjectException如果每条消息都低于200kb,我得到了一个

  3. 添加一个Thread.sleep(1)似乎已经解决了这个问题.我不能得到一个例外Thread.sleep

通过Android C++代码,似乎transaction失败的原因不明,并被解释为其中一个异常

问题

  1. 什么是" transaction"?
  2. 什么定义了交易中的内容?在给定时间内是一定数量的事件吗?或者只是最大数量/大小的事件?
  3. 有没有办法"刷新"交易或等待交易完成?
  4. 什么是避免这些错误的正确方法?(注意:将其分解为更小的部分只会引发不同的异常)


AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.boundservicestest"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <service android:name=".BoundService" android:process=":separate"/>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

MainActivity.kt

class MainActivity : AppCompatActivity() {

    private lateinit var sendDataButton: Button
    private val myServiceConnection: MyServiceConnection = MyServiceConnection(this)

    override fun onCreate(savedInstanceState: Bundle?) { …
Run Code Online (Sandbox Code Playgroud)

android transactions ipc android-service android-binder

15
推荐指数
2
解决办法
2918
查看次数

使用ParcelFileDescriptor.createPipe()将InputStream传输到另一个服务(跨进程边界),并使用"EBADF(错误的文件编号)"

我想通过使用ParcelFileDescriptor.createPipe()一个流到流的复制线程和一个ParcelFileDescriptor,将一个Android服务从一个Android服务"发送"到一个不同进程中运行的另一个服务,该表示管道的读取端,它被提供给另一个服务借助Binder IPC.

发送代码(流程A)

我想将一个给定的InputStream发送到接收服务:

public sendInputStream() {
    InputStream is = ...; // that's the stream for process/service B
    ParcelFileDescriptor pdf = ParcelFileDescriptorUtil.pipeFrom(is);
    inputStreamService.inputStream(pdf);
}
Run Code Online (Sandbox Code Playgroud)

ParcelFileDescriptorUtil是一个帮助器类,具有经典的java.io.流到流复制线程:

public class ParcelFileDescriptorUtil {

    public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException {
        ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
        ParcelFileDescriptor readSide = pipe[0];
        ParcelFileDescriptor writeSide = pipe[1];

        // start the transfer thread
        new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide)).start();

        return readSide;
    }

    static class TransferThread extends Thread {
        final InputStream mIn;
        final OutputStream mOut;

        TransferThread(InputStream in, OutputStream …
Run Code Online (Sandbox Code Playgroud)

android ipc pipe android-service android-binder

12
推荐指数
1
解决办法
8031
查看次数