1 /* 2 * Copyright (C) 2017 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 com.android.layoutlib.bridge.remote.client.adapters; 18 19 import com.android.ide.common.rendering.api.IImageFactory; 20 import com.android.ide.common.rendering.api.RenderParams; 21 import com.android.ide.common.rendering.api.SessionParams; 22 import com.android.ide.common.rendering.api.SessionParams.Key; 23 import com.android.layout.remote.api.RemoteAssetRepository; 24 import com.android.layout.remote.api.RemoteHardwareConfig; 25 import com.android.layout.remote.api.RemoteLayoutLog; 26 import com.android.layout.remote.api.RemoteLayoutlibCallback; 27 import com.android.layout.remote.api.RemoteRenderParams; 28 import com.android.layout.remote.api.RemoteRenderResources; 29 import com.android.layout.remote.api.RemoteSessionParams; 30 import com.android.tools.layoutlib.annotations.NotNull; 31 import com.android.tools.layoutlib.annotations.Nullable; 32 33 import java.rmi.RemoteException; 34 import java.rmi.server.UnicastRemoteObject; 35 36 public class RemoteRenderParamsAdapter implements RemoteRenderParams { 37 private final RenderParams mDelegate; 38 39 protected RemoteRenderParamsAdapter(@NotNull RenderParams params) { 40 mDelegate = params; 41 } 42 43 public static RemoteSessionParams create(@NotNull SessionParams params) throws RemoteException { 44 return (RemoteSessionParams) UnicastRemoteObject.exportObject( 45 new RemoteRenderParamsAdapter(params), 0); 46 } 47 48 @Nullable 49 @Override 50 public String getProjectKey() { 51 Object projectKey = mDelegate.getProjectKey(); 52 // We can not transfer a random object so let's send just a string 53 return projectKey != null ? projectKey.toString() : null; 54 } 55 56 @Override 57 public RemoteHardwareConfig getRemoteHardwareConfig() { 58 return new RemoteHardwareConfig(mDelegate.getHardwareConfig()); 59 } 60 61 @Override 62 public int getMinSdkVersion() { 63 return mDelegate.getMinSdkVersion(); 64 } 65 66 @Override 67 public int getTargetSdkVersion() { 68 return mDelegate.getTargetSdkVersion(); 69 } 70 71 @Override 72 public RemoteRenderResources getRemoteResources() { 73 try { 74 return RemoteRenderResourcesAdapter.create(mDelegate.getResources()); 75 } catch (RemoteException e) { 76 throw new RuntimeException(e); 77 } 78 } 79 80 @Override 81 public RemoteAssetRepository getAssets() { 82 try { 83 return RemoteAssetRepositoryAdapter.create(mDelegate.getAssets()); 84 } catch (RemoteException e) { 85 throw new RuntimeException(e); 86 } 87 } 88 89 @Override 90 public RemoteLayoutlibCallback getRemoteLayoutlibCallback() { 91 try { 92 return RemoteLayoutlibCallbackAdapter.create(mDelegate.getLayoutlibCallback()); 93 } catch (RemoteException e) { 94 throw new RuntimeException(e); 95 } 96 } 97 98 @Override 99 public RemoteLayoutLog getLog() { 100 try { 101 return RemoteLayoutLogAdapter.create(mDelegate.getLog()); 102 } catch (RemoteException e) { 103 throw new RuntimeException(e); 104 } 105 } 106 107 @Override 108 public boolean isBgColorOverridden() { 109 return mDelegate.isBgColorOverridden(); 110 } 111 112 @Override 113 public int getOverrideBgColor() { 114 return mDelegate.getOverrideBgColor(); 115 } 116 117 @Override 118 public long getTimeout() { 119 return mDelegate.getTimeout(); 120 } 121 122 @Override 123 public IImageFactory getImageFactory() { 124 return mDelegate.getImageFactory(); 125 } 126 127 @Override 128 public String getAppIcon() { 129 return mDelegate.getAppIcon(); 130 } 131 132 @Override 133 public String getAppLabel() { 134 return mDelegate.getAppLabel(); 135 } 136 137 @Override 138 public String getLocale() { 139 return mDelegate.getLocale(); 140 } 141 142 @Override 143 public String getActivityName() { 144 return mDelegate.getActivityName(); 145 } 146 147 @Override 148 public boolean isForceNoDecor() { 149 return mDelegate.isForceNoDecor(); 150 } 151 152 @Override 153 public boolean isRtlSupported() { 154 return mDelegate.isRtlSupported(); 155 } 156 157 @Override 158 public <T> T getFlag(Key<T> key) { 159 return mDelegate.getFlag(key); 160 } 161 } 162