Home | History | Annotate | Download | only in producer
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.perfetto.producer;
     18 
     19 import android.app.Notification;
     20 import android.app.Service;
     21 import android.os.IBinder;
     22 import android.content.Intent;
     23 
     24 public class ProducerIsolatedService extends Service {
     25     private static final int NOTIFICATION_ID = 123;
     26 
     27     @Override
     28     public void onCreate() {
     29         Notification.Builder builder = new Notification.Builder(this, "isolated_service");
     30         builder.setContentTitle("Perfetto isolated service")
     31                 .setContentText("Perfetto isolated service")
     32                 .setSmallIcon(R.mipmap.ic_launcher);
     33 
     34         startForeground(NOTIFICATION_ID, builder.build());
     35 
     36         System.loadLibrary("perfettocts_jni");
     37         new Thread(new Runnable() {
     38             @Override
     39             public void run() {
     40                 try {
     41                     setupProducer();
     42                 } catch (Exception ex) {
     43                     ex.printStackTrace();
     44                 }
     45             }
     46         })
     47                 .start();
     48     }
     49 
     50     @Override
     51     public int onStartCommand(Intent intent, int flags, int startId) {
     52         return START_STICKY;
     53     }
     54 
     55     @Override
     56     public IBinder onBind(Intent intent) {
     57         return null;
     58     }
     59 
     60     @Override
     61     public void onDestroy() {}
     62 
     63     private static native void setupProducer();
     64 }
     65