1. Download our Official Android App: Forums for Android!

Apps Isolate a Service in Android application (AndroidStudio)

Discussion in 'Android Development' started by Parul, May 16, 2016.

  1. Parul

    Parul Lurker
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    5
    Joined:
    May 16, 2016

    May 16, 2016
    5
    1
    16
    Male
    Hi,

    I am new to world of Android Development and experimenting on Isolation of services in Android. For the purpose, I created an application that play a music file on button press. Whenever i am trying to put isolation flag to true. The application flag crashes

    android:isolatedProcess="true". My application crashes. Following is the code. Can anyone help any corrections.
    Thanks in advance.

    Code (Text):
    1. Manifest
    2.  
    3. <?xml version="1.0" encoding="utf-8"?>
    4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    5.     package="org.o7planning.playsongservice">
    6.  
    7.     <application
    8.         android:allowBackup="true"
    9.         android:icon="@mipmap/ic_launcher"
    10.         android:label="@string/app_name"
    11.         android:supportsRtl="true"
    12.         android:theme="@style/AppTheme">
    13.         <activity android:name=".MainActivity">
    14.             <intent-filter>
    15.                 <action android:name="android.intent.action.MAIN" />
    16.  
    17.                 <category android:name="android.intent.category.LAUNCHER" />
    18.             </intent-filter>
    19.         </activity>
    20.  
    21.         <service
    22.             android:name=".PlaySongService"
    23.             android:enabled="true"
    24.             android:isolatedProcess="true"
    25.             android:exported="true"></service>
    26.     </application>
    27.  
    28. </manifest>

    Code (Text):
    1. MainActivity
    2.  
    3. package org.o7planning.playsongservice;
    4.  
    5. import android.app.Activity;
    6. import android.content.Context;
    7. import android.content.ComponentName;
    8. import android.content.Intent;
    9. import android.content.ServiceConnection;
    10. import android.support.v7.app.AppCompatActivity;
    11. import android.os.Bundle;
    12. import android.view.View;
    13. import android.os.IBinder;
    14. import android.widget.Toast;
    15.  
    16. import android.view.View;
    17.  
    18. public class MainActivity extends AppCompatActivity {
    19.             PlaySongService localService;
    20.         private boolean isBound = false;
    21.         @Override
    22.     protected void onCreate(Bundle savedInstanceState) {
    23.         super.onCreate(savedInstanceState);
    24.         setContentView(R.layout.activity_main);
    25.     }
    26.  
    27.     // This method is called when users click on the Start button.
    28.     public void playSong(View view)  {
    29.         // Create Intent object for PlaySongService.
    30.  
    31.         Intent myIntent = new Intent(MainActivity.this, PlaySongService.class);
    32.         bindService(myIntent, connection, Context.BIND_AUTO_CREATE);
    33.  
    34.         // Call startService with Intent parameter.
    35.         if (isBound) {
    36.             this.startService(myIntent);
    37.           //  myIntent.putExtra("pass","Activity is communicating with service");
    38.         }
    39.  
    40.     }
    41.     private ServiceConnection connection = new ServiceConnection() {
    42.         @Override
    43.         public void onServiceConnected(ComponentName className, IBinder service) {
    44.             PlaySongService.LocalBinder binder = (PlaySongService.LocalBinder) service;
    45.             localService = binder.getService();
    46.             isBound = true;
    47.         }
    48.         @Override
    49.         public void onServiceDisconnected(ComponentName arg0) {
    50.             isBound = false;
    51.         }
    52.     };
    53. }
    54.     // This method is called when users click on the Stop button.
    55. //   public void stopSong(View view)  {
    56.  
    57.        // Create Intent object
    58.    //    Intent myIntent = new Intent(MainActivity.this, PlaySongService.class);
    59.      //   this.stopService(myIntent);
    60.    //}
    61.  
    62.  
    63.  
    64. //}

     

    Advertisement

  2. Unforgiven

    Unforgiven OK Google
    Moderator
    Rank:
     #1
    Points:
    4,238
    Posts:
    36,301
    Joined:
    Jun 23, 2010

    Jun 23, 2010
    36,301
    42,410
    4,238
    Male
    Douglas, MA
    Application Development thread moved to the Development forum for better exposure.:)
     
  3. Parul

    Parul Lurker
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    5
    Joined:
    May 16, 2016

    May 16, 2016
    5
    1
    16
    Male
    Thank you Unforgiven :D
     
    Unforgiven likes this.
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,844
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,844
    11,445
    1,988
    Male
    Software developer
    South West of England
    Can you please post the stack trace from your Logcat, when your app crashes?
     
  5. Parul

    Parul Lurker
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    5
    Joined:
    May 16, 2016

    May 16, 2016
    5
    1
    16
    Male
    Code (Text):
    1. 05-16 16:28:10.751 24207-24207/org.o7planning.playsongservice I/Process: Sending signal. PID: 24207 SIG: 9
    2. 05-16 16:28:24.897 24503-24503/org.o7planning.playsongservice W/System: ClassLoader referenced unknown path: /data/app/org.o7planning.playsongservice-1/lib/x86
    3. 05-16 16:28:25.153 24503-24503/org.o7planning.playsongservice W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
    4. 05-16 16:28:25.341 24503-24539/org.o7planning.playsongservice D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
    5.                                                                                
    6.                                                                                 [ 05-16 16:28:25.343 24503:24503 D/         ]
    7.                                                                                 HostConnection::get() New Host Connection established 0xaa467b90, tid 24503
    8. 05-16 16:28:25.430 24503-24539/org.o7planning.playsongservice I/OpenGLRenderer: Initialized EGL, version 1.4
    9. 05-16 16:28:25.481 24503-24539/org.o7planning.playsongservice W/EGL_emulation: eglSurfaceAttrib not implemented
    10. 05-16 16:28:25.481 24503-24539/org.o7planning.playsongservice W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa14a960, error=EGL_SUCCESS
    11. 05-16 16:28:27.213 24565-24565/org.o7planning.playsongservice:hello W/System: ClassLoader referenced unknown path: /data/app/org.o7planning.playsongservice-1/lib/x86
    12. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:41): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    13. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:42): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    14. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:43): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    15. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:44): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    16. 05-16 16:28:27.214 24565-24565/org.o7planning.playsongservice:hello W/ContextImpl: Unable to create files subdir /data/user/0/org.o7planning.playsongservice/cache
    17. 05-16 16:28:27.214 24565-24565/org.o7planning.playsongservice:hello D/AndroidRuntime: Shutting down VM
    18. 05-16 16:28:27.215 24565-24565/org.o7planning.playsongservice:hello E/AndroidRuntime: FATAL EXCEPTION: main
    19.                                                                                       Process: org.o7planning.playsongservice:hello, PID: 24565
    20.                                                                                       java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference
    21.                                                                                           at android.app.LoadedApk.makeApplication(LoadedApk.java:578)
    22.                                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
    23.                                                                                           at android.app.ActivityThread.-wrap1(ActivityThread.java)
    24.                                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    25.                                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
    26.                                                                                           at android.os.Looper.loop(Looper.java:148)
    27.                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
    28.                                                                                           at java.lang.reflect.Method.invoke(Native Method)
    29.                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    30.                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    31.                                                                                        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference
    32.                                                                                           at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:233)
    33.                                                                                           at android.app.Application.attach(Application.java:187)
    34.                                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:997)
    35.                                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:981)
    36.                                                                                           at android.app.LoadedApk.makeApplication(LoadedApk.java:573)
    37.                                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
    38.                                                                                           at android.app.ActivityThread.-wrap1(ActivityThread.java)
    39.                                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    40.                                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
    41.                                                                                           at android.os.Looper.loop(Looper.java:148)
    42.                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
    43.                                                                                           at java.lang.reflect.Method.invoke(Native Method)
    44.                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    45.                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    46. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:45): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    47. 05-16 16:28:27.207 24565-24565/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:46): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    48. 05-16 16:28:29.690 24565-24565/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 24565 SIG: 9
    49. 05-16 16:28:42.040 24632-24632/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 24632 SIG: 9
    50. 05-16 16:30:03.940 24503-24539/org.o7planning.playsongservice E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40d6fa0
    51. 05-16 16:30:11.914 24503-24539/org.o7planning.playsongservice I/OpenGLRenderer: Initialized EGL, version 1.4
    52. 05-16 16:30:11.956 24503-24539/org.o7planning.playsongservice W/EGL_emulation: eglSurfaceAttrib not implemented
    53. 05-16 16:30:11.956 24503-24539/org.o7planning.playsongservice W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa46f8c0, error=EGL_SUCCESS
    54. 05-16 16:34:44.001 24503-24539/org.o7planning.playsongservice E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa3f70e0
    55. 05-16 16:35:35.059 24503-24539/org.o7planning.playsongservice W/EGL_emulation: eglSurfaceAttrib not implemented
    56. 05-16 16:35:35.059 24503-24539/org.o7planning.playsongservice W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa46f8c0, error=EGL_SUCCESS
    57. 05-16 16:35:36.075 24503-24539/org.o7planning.playsongservice E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40d7010
    58. 05-16 16:35:56.782 24503-24539/org.o7planning.playsongservice I/OpenGLRenderer: Initialized EGL, version 1.4
    59. 05-16 16:35:56.820 24503-24539/org.o7planning.playsongservice W/EGL_emulation: eglSurfaceAttrib not implemented
    60. 05-16 16:35:56.821 24503-24539/org.o7planning.playsongservice W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa46fe20, error=EGL_SUCCESS
    61. 05-16 16:35:57.803 24503-24539/org.o7planning.playsongservice E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa3f70e0
    62. 05-17 02:19:30.688 24503-24509/org.o7planning.playsongservice W/art: Suspending all threads took: 5.638ms
    63. 05-17 10:06:41.769 24503-24509/org.o7planning.playsongservice W/art: Suspending all threads took: 5.639ms
    64.  
     
  6. Parul

    Parul Lurker
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    5
    Joined:
    May 16, 2016

    May 16, 2016
    5
    1
    16
    Male
    This is the logcat when android exported is also set to true

    Code (Text):
    1. 05-17 13:17:04.770 12179-12179/org.o7planning.playsongservice:hello W/System: ClassLoader referenced unknown path: /data/app/org.o7planning.playsongservice-2/lib/x86
    2. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:77): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    3. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:78): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    4. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:79): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    5. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:80): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    6. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:81): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    7. 05-17 13:17:04.767 12179-12179/org.o7planning.playsongservice:hello W/ngservice:hello: type=1400 audit(0.0:82): avc: denied { search } for name="org.o7planning.playsongservice" dev="vdc" ino=22398 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
    8. 05-17 13:17:04.772 12179-12179/org.o7planning.playsongservice:hello W/ContextImpl: Unable to create files subdir /data/user/0/org.o7planning.playsongservice/cache
    9. 05-17 13:17:04.772 12179-12179/org.o7planning.playsongservice:hello D/AndroidRuntime: Shutting down VM
    10. 05-17 13:17:04.773 12179-12179/org.o7planning.playsongservice:hello E/AndroidRuntime: FATAL EXCEPTION: main
    11.                                                                                       Process: org.o7planning.playsongservice:hello, PID: 12179
    12.                                                                                       java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference
    13.                                                                                           at android.app.LoadedApk.makeApplication(LoadedApk.java:578)
    14.                                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
    15.                                                                                           at android.app.ActivityThread.-wrap1(ActivityThread.java)
    16.                                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    17.                                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
    18.                                                                                           at android.os.Looper.loop(Looper.java:148)
    19.                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
    20.                                                                                           at java.lang.reflect.Method.invoke(Native Method)
    21.                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    22.                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    23.                                                                                        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference
    24.                                                                                           at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:233)
    25.                                                                                           at android.app.Application.attach(Application.java:187)
    26.                                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:997)
    27.                                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:981)
    28.                                                                                           at android.app.LoadedApk.makeApplication(LoadedApk.java:573)
    29.                                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
    30.                                                                                           at android.app.ActivityThread.-wrap1(ActivityThread.java)
    31.                                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    32.                                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
    33.                                                                                           at android.os.Looper.loop(Looper.java:148)
    34.                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
    35.                                                                                           at java.lang.reflect.Method.invoke(Native Method)
    36.                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    37.                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    38. 05-17 13:17:06.953 12179-12179/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 12179 SIG: 9
    39. 05-17 13:17:12.954 12277-12277/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 12277 SIG: 9
    40. 05-17 13:18:50.234 15126-15126/org.o7planning.playsongservice W/System: ClassLoader referenced unknown path: /data/app/org.o7planning.playsongservice-1/lib/x86
    41. 05-17 13:18:50.712 15126-15126/org.o7planning.playsongservice W/System: ClassLoader referenced unknown path: /data/app/org.o7planning.playsongservice-1/lib/x86
    42. 05-17 13:18:50.847 15126-15126/org.o7planning.playsongservice W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
    43. 05-17 13:18:51.146 15126-15178/org.o7planning.playsongservice D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
    44.                                                                                
    45.                                                                                 [ 05-17 13:18:51.149 15126:15126 D/         ]
    46.                                                                                 HostConnection::get() New Host Connection established 0xaa47dfd0, tid 15126
    47. 05-17 13:18:51.339 15126-15178/org.o7planning.playsongservice I/OpenGLRenderer: Initialized EGL, version 1.4
    48. 05-17 13:18:51.405 15126-15178/org.o7planning.playsongservice W/EGL_emulation: eglSurfaceAttrib not implemented
    49. 05-17 13:18:51.405 15126-15178/org.o7planning.playsongservice W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa1508e0, error=EGL_SUCCESS
    50. 05-17 13:18:55.822 15248-15248/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 15248 SIG: 9
    51. 05-17 13:18:58.569 15348-15348/org.o7planning.playsongservice:hello I/Process: Sending signal. PID: 15348 SIG: 9
     

Share This Page

Loading...