확장 프로그램 앱 및 로컬 명령어

AMAPI (Android Management API) SDK를 사용하면 EMM 지정 확장 앱이 다음과 같은 작업을 할 수 있습니다. Android Device Policy (ADP)와 직접 통신하고 Commands를 실행합니다. 할 수 있습니다.

AMAPI SDK와 통합에서는 이 라이브러리를 애플리케이션에 추가하는 방법을 설명합니다.

SDK가 통합되면 확장 프로그램 앱이 ADP와 통신하여 다음을 수행할 수 있습니다.

명령어 실행

확장 프로그램 앱은 ADP를 사용하여 실행할 명령어를 요청할 수 있습니다. IssueCommandRequest에는 다음에 관한 세부정보를 포함할 요청 객체가 포함됩니다. 지정할 수 있습니다.

다음 스니펫은 패키지 데이터 삭제 요청을 실행하는 방법을 보여줍니다.

import android.util.Log;
...
import com.google.android.managementapi.commands.LocalCommandClientFactory;
import com.google.android.managementapi.commands.model.Command;
import com.google.android.managementapi.commands.model.GetCommandRequest;
import com.google.android.managementapi.commands.model.IssueCommandRequest;
import com.google.android.managementapi.commands.model.IssueCommandRequest.ClearAppsData;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;

...
 
void issueClearAppDataCommand(ImmutableList<String> packageNames) {
   
Futures.addCallback(
       
LocalCommandClientFactory.create(getContext())
           
.issueCommand(createClearAppRequest(packageNames)),
       
new FutureCallback<Command>() {
         
@Override
         
public void onSuccess(Command result) {
           
// Process the returned command result here
           
Log.i(TAG, "Successfully issued command");
         
}

         
@Override
         
public void onFailure(Throwable t) {
           
Log.e(TAG, "Failed to issue command", t);
         
}
       
},
       
MoreExecutors.directExecutor());
 
}

 
IssueCommandRequest createClearAppRequest(ImmutableList<String> packageNames) {
   
return IssueCommandRequest.builder()
       
.setClearAppsData(
           
ClearAppsData.builder()
               
.setPackageNames(packageNames)
               
.build()
       
)
       
.build();
 
}
...

이전 예는 지정된 앱에 대해 명확한 앱 데이터 요청을 실행하는 방법을 명령이 성공적으로 실행될 때까지 기다리는 것을 의미합니다. 만약 실행되면 Command 객체가 현재 나중에 애플리케이션의 상태를 쿼리하는 데 사용할 수 있는 실행할 수 있습니다

명령어 가져오기

확장 프로그램 앱은 이전에 실행된 명령 요청의 상태를 쿼리할 수 있습니다. 받는사람 명령어 상태를 검색하려면 명령어 요청)을 실행합니다. 다음 스니펫은 ADP로 GetCommandRequest

import android.util.Log;
...
import com.google.android.managementapi.commands.LocalCommandClientFactory;
...
import com.google.android.managementapi.commands.model.GetCommandRequest;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;

...
 
void getCommand(String commandId) {
   
Futures.addCallback(
       
LocalCommandClientFactory.create(getApplication())
           
.getCommand(GetCommandRequest.builder().setCommandId(commandId).build()),
       
new FutureCallback<Command>() {
         
@Override
         
public void onSuccess(Command result) {
           
// Process the returned command result here
           
Log.i(Constants.TAG, "Successfully issued command");
         
}

         
@Override
         
public void onFailure(Throwable t) {
           
Log.e(Constants.TAG, "Failed to issue command", t);
         
}
       
},
       
MoreExecutors.directExecutor());
 
}
 
...

명령어 상태 변경 콜백 수신 대기

확장 프로그램 앱은 상태 변경 업데이트를 수신하기 위해 콜백을 등록할 수 있습니다. 명령어를 실행해 보겠습니다

  1. 명령어 상태 변경사항이 CommandListener에 알림으로 전달됩니다. 이를 구현합니다. 인터페이스를 구현하고 님이 상태 업데이트를 수신했습니다.
  2. NotificationReceiverService를 확장하고 CommandListener를 제공합니다. 인스턴스를 만들 수 있습니다
  3. Android에서 확장된 NotificationReceiverService의 클래스 이름 지정 Management API 정책 (정책 구성 참고)

    import com.google.android.managementapi.commands.CommandListener;
    import com.google.android.managementapi.notification.NotificationReceiverService;

    ...

    public class SampleCommandService extends NotificationReceiverService {

     
    @Override
     
    protected void setupInjection() {
       
    // (Optional) If using DI and needs initialisation then use this method.
     
    }

     
    @Override
     
    public CommandListener getCommandListener() {
       
    // return the concrete implementation from previous step
       
    return ...;
     
    }
    }
  4. 서비스를 AndroidManifest.xml에 추가하고 서비스가 내보내졌는지 확인합니다.

    <service
     
    android:name = ".notification.SampleCommandService"
     
    android:exported = "true" />

정책 구성

확장 프로그램 앱이 ADP와 직접 통신하도록 하려면 EMM은 extensionConfig 정책을 제공해야 합니다.

 "applications": [{
   
"packageName": "com.amapi.extensibility.demo",
   
...
   
"extensionConfig": {
     
"signingKeyFingerprintsSha256": [
       
// Include signing key of extension app
     
],
     
// Optional if callback is implemented
     
"notificationReceiver": "com.amapi.extensibility.demo.notification.SampleCommandService"
   
}
 
}]

테스트

단위 테스트

LocalCommandClient는 인터페이스이므로 테스트 가능한 있습니다.

통합 테스트

ADP로 테스트하려면 다음 정보가 필요합니다.

  1. 확장 프로그램 앱의 패키지 이름입니다.
  2. 앱과 연결된 서명의 16진수로 인코딩된 SHA-256 해시입니다. 패키지에서 찾을 수 있습니다.
  3. 콜백을 테스트하는 경우 선택적으로, 콜백 지원을 위해 새로 도입된 서비스입니다. (정규화된 이름: CommandService)을 입력합니다.