Cannot resolve symbol "IPackageDeleteObserver" - java

I am trying to uninstall the piracy application. I don't have the following imports in my sdk .
import android.app.PackageDeleteObserver;
import android.content.pm.IPackageDeleteObserver;
So i got the interface IPackageDeleteObserver from here https://github.com/android/platform_frameworks_base/blob/master/core/java/android/content/pm/IPackageInstallObserver2.aidl which i placed in the android/content/pm but my android studio does not detect it. Dropdown does not show android.content.pm.IPackageDeleteObserver . Does anybody knows how to solve these imports?
Here it's the whole code:
package com.vivek.light.utils;
/**
* Created by Shiva on 24-07-2015.
*/
import android.app.PackageDeleteObserver;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.util.Log;
import java.lang.reflect.Method;
import static com.vivek.light.utils.AntiPiracyConstants.*;
public class AntiPiracyUtils {
static final String TAG = "ANTI-PIRACY: Utilities";
private static PackageDeleteObserver sPDO;
private AntiPiracyUtils() {
sPDO = getPackageDeleteObserver();
}
private static Class<?>[] UNINSTALLTYPES = new Class[] {
String.class, IPackageDeleteObserver.class, int.class
};
public static class PackageDeleteObserver extends IPackageDeleteObserver.stub {
public void packageDeleted(String packageName, int returnCode) throws RemoteException {
if (DEBUG) Log.i(TAG, "PackageDeleteObserver: " + packageName + " removed");
}
}
public static PackageDeleteObserver getPackageDeleteObserver() {
if (sPDO == null) sPDO = new PackageDeleteObserver();
return sPDO;
}
public static Method getUninstallTypes(PackageManager pm) throws NoSuchMethodException {
try {
return pm.getClass().getMethod("deletePackage", UNINSTALLTYPES);
} catch (NoSuchMethodException WTF) {
Log.e(TAG, "NoSuchMethodException" + l);
}
return null;
}
}

Related

Browser is not launching for the second TestNG Test case

The browser is not launching for the second testcase of a TestNG Test group.
Tried playing with the Before and AfterTest but still the browser is not launching. also add checks the browser running. not sure what I miss here.
Error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#Email"}
(Session info: chrome=91.0.4472.77)
this causes the b browser is not launched at the time
Driver Class:
package com.portalHelpers;
import org.openqa.selenium.Alert;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.util.Date;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import static java.lang.String.valueOf;
public class WebDriverHelper extends EventFiringWebDriver {
public static RemoteWebDriver remoteDriver;
protected static HtmlUnitDriver htmlDriver;
protected static Alert _alert;
protected static DriverService cds;
private static String driverClass = System.getProperty("driverClass");
public static long now = new Date().getTime();
public static com.itextpdf.text.Document dataFeed;
public final static String DefaultTimeOut = "40000";
public final static int TimeOut = 90;
protected static String chrome_driver_location = "/Users/me/Downloads/chromedriver";
public static String url = System.getProperty("url");
public static String browser = System.getProperty("browser");
private static String platform = Platform.getCurrent().name();
private static String CHROME_DRIVER = "chrome_driver";
//******************URLs************************************************************//
public static String url_test = "www.google.com";
public static String url_live = "www.google.com";
//******************Browser settings************************************************************//
//Browser settings
static {
//
if (browser.equalsIgnoreCase("chrome")) {
if (platform.equalsIgnoreCase("Mac")) {
CHROME_DRIVER = CHROME_DRIVER + "_mac";
} else if (platform.equalsIgnoreCase("LINUX")) {
CHROME_DRIVER = CHROME_DRIVER + "_linux";
} else {
CHROME_DRIVER = CHROME_DRIVER + "_win.exe";
}
setWebDriverToChrome();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
remoteDriver.close();
}
});
}
static {
if (url.equalsIgnoreCase("url_test")) {
open_test();
} else if (url.equalsIgnoreCase("url_live")) {
open_live();
}
}
public WebDriverHelper() {
super(remoteDriver);
manage().window().maximize();
manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
#BeforeTest
public void setUp () throws Exception{
setWebDriverToChrome();}
#AfterTest
public void tearDown () throws Exception{
if(remoteDriver !=null){
remoteDriver.close();
}}
public static void setWebDriverToChrome () {
System.setProperty("webdriver.chrome.driver",chrome_driver_location);
cds = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chrome_driver_location))
.usingAnyFreePort()
.build();
try {
cds.start();
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
}
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
remoteDriver = new RemoteWebDriver(cds.getUrl(), opt);
}
public void openWebPage (String url){
//Get url and maximize the window
remoteDriver.get(url);
remoteDriver.manage().window().maximize();
}
public static void open_test () {
remoteDriver.get(url_test);
remoteDriver.manage().window().maximize();
}
public static void open_live() {
remoteDriver.get(url_live);
// remoteDriver.manage().window().maximize();
}
public static WebDriver getSelenium () {
if ((remoteDriver == null) && (!"noBrowser".equals(driverClass))) {
throw new IllegalStateException("Selenium client is not initialised.");
}
return remoteDriver;
}
}
Test Class:
package Testsuites;
import com.portalHelpers.PageObjects;
import com.portalHelpers.WebDriverHelper;
import com.portalHelpers.SeleniumMethodsHelper;
import org.testng.Assert;
import org.testng.annotations.Test;
public class testSuite extends WebDriverHelper {
PageObjects pageObjects = new PageObjects();
SeleniumMethodsHelper seleniumMethodsHelper = new SeleniumMethodsHelper();
String user1 = "user1t#google.com";
String standardPass = "1234";
String user2 = "user2#gmail.com";
#Test(groups = "MainFlowTests")
public void preparation(){
String actual_url = getCurrentUrl();
System.out.println(actual_url);
//sending the username and password parameters to the login method//
PageObjects.login_logic(remoteDriver,user1, standardPass);
//Asserting the user logged in is the one we used and that we are on logged in//
String name = PageObjects.account_Email().getText();
System.out.println(name);
Assert.assertEquals(name,useer1);
seleniumMethodsHelper.sleep(3);
SeleniumMethodsHelper.mouseOver(PageObjects.promo_Button());
seleniumMethodsHelper.sleep(8);
}
#Test(groups = "MainFlowTests")
public void offerCreation(){
String actual_url = getCurrentUrl();
System.out.println(actual_url);
//sending the username and password parameters to the login method//
//PageObjects.email_Field().click();
PageObjects.login_logic(remoteDriver,dryFoodsCam, standardPass);
seleniumMethodsHelper.sleep(3);
}
}
Image shows the TestNG configuration.
Hope you can find what I miss here or if something is wrong.
Thanks

How to connect to ACR122 with CardService

I'm writing a program (Java Application) for reading ePassport. For access I use the library org.jmrtd. What kind of object should I transfer in CardService.getInstance() ?
import net.sf.scuba.smartcards.CardService;
import net.sf.scuba.smartcards.CardServiceException;
import org.jmrtd.BACKeySpec;
import org.jmrtd.PassportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestComponent {
private static final Logger log = LoggerFactory.getLogger(MainApp.class);
public static void main(String args[]) {
try {
CardService cs = CardService.getInstance(???????);
PassportService ps = new PassportService(cs);
ps.open();
ps.sendSelectApplet(false);
ps.sendSelectApplet(false);
BACKeySpec bacKey = new BACKeySpec() {
public String getDocumentNumber() {
return "xxxxxxxx";
}
public String getDateOfBirth() {
return "yyMMdd";
}
public String getDateOfExpiry() {
return "yyMMdd";
}
};
ps.doBAC(bacKey);
ps.close();
} catch (CardServiceException e) {
e.printStackTrace();
}
}
}
Answer found:
add in pom
net.sf.scuba
scuba-sc-j2se
0.0.13
import net.sf.scuba.smartcards.TerminalCardService;
CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0);
CardService cs = CardService.getInstance(terminal);
PassportService ps = new PassportService(cs);
ps.open();

PlayFramework how to access list from super controller

I am completing my university project, but I encountered weird problem. Since I am a student, apologize in the adavance if it is prosaic.
I have my BasicCommonController which has List backendErrors = new ArrayList<>()
, and I have another Controller which extends BasicCommonController, and I'm able to access backendErrors list from BasicCommonController, but I am not able
to put new Element to the list, wchich is always empty. I have tried to access via super.backendErrors, but it also does not work.
How to add some error to the super.backendErrors and access it in another Controllers
this is abstract controller:
package controllers;
import org.apache.commons.lang3.StringUtils;
import play.Logger;
import play.Play;
import play.mvc.Controller;
import java.util.ArrayList;
import java.util.List;
/**
* Created by vv on 22.04.2017.
*/
public class BasicAbstractController extends Controller {
public static final String GO_HOME = "/";
public List<String> backendErrors = new ArrayList<>();
public static String getPlaceToObserve(){
String place = Play.application().configuration().getString("storage.place");
if(StringUtils.isNotBlank(place)){
return place;
}
return StringUtils.EMPTY;
}
public static String getServerInstance(){
String instance = Play.application().configuration().getString("storage.place");
if(StringUtils.isNotBlank(instance)){
return instance;
}
return StringUtils.EMPTY;
}
}
this is example controller
package controllers;
import com.google.common.io.Files;
import com.sun.org.apache.regexp.internal.RE;
import constans.AppCommunicates;
import play.Logger;
import play.mvc.Http;
import play.mvc.Result;
import util.FileUtil;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* Created by vv on 22.04.2017.
*/
public class FileUploadController extends BasicAbstractController {
public Result upload() {
Http.MultipartFormData<File> body = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart<File> picture = body.getFile("picture");
if (picture != null) {
String fileName = picture.getFilename();
String contentType = picture.getContentType();
File file = picture.getFile();
File fileToSave = new File(getPlaceToObserve() + "/" + picture.getFilename());
try{
Files.copy(file,fileToSave);
}
catch (IOException ioe){
Logger.error("Unable to write file");
}
Logger.error("File Handled Cuccessfully");
return redirect(GO_HOME);
} else {
flash("error", "Missing file");
return badRequest();
}
}
public Result delete(String fileName){
List<File> files = FileUtil.getCurrentFileNames();
File fileToDelete = null;
for (File file : files) {
if(file.getName().equals(fileName)){
fileToDelete = file;
break;
}
}
boolean deletionResult = FileUtil.deleteGivenFile(fileToDelete);
if(!deletionResult){
// i am not able to add smthg here
backendErrors.add(AppCommunicates.UNABLE_TO_DELETE_FILE);
}
return redirect(GO_HOME);
}
}
I am not able to add nor access list from other controllers

Web-Based Java Compiler

I'm Trying to create an online compiler that takes the the code as a string from the web page and displays the output. I've created a servlet.The user will enetr the program code in a textarea named "uName". The code to take the input as a string and compile it is as follows
`enter code here`
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Org.WebApplication1.test;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletException;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
class CompileString {
static String program;
CompileString(String s)
{
program=s;
}
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
Iterable<? extends JavaFileObject> fileObjects;
fileObjects = getJavaSourceFromString(program);
compiler.getTask(null, null, null, null, null, fileObjects).call();
Class<?> clazz = Class.forName("Test");
Method m = clazz.getMethod("main", new Class[] { String[].class });
Object[] _args = new Object[] { new String[0] };
m.invoke(null, _args);
}
static Iterable<JavaSourceFromString> getJavaSourceFromString(String code) {
final JavaSourceFromString jsfs;
jsfs = new JavaSourceFromString("code", code);
return new Iterable<JavaSourceFromString>() {
public Iterator<JavaSourceFromString> iterator() {
return new Iterator<JavaSourceFromString>() {
boolean isNext = true;
public boolean hasNext() {
return isNext;
}
public JavaSourceFromString next() {
if (!isNext)
throw new NoSuchElementException();
isNext = false;
return jsfs;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
}
class JavaSourceFromString extends SimpleJavaFileObject {
final String code;
JavaSourceFromString(String name, String code) {
super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
this.code = code;
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
}
}
/**
*
* #author RAJ
*/
public class ServletExample extends HttpServlet{
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//super.doGet(req, resp);
String name=req.getParameter("uName");
CompileString obj=new CompileString(name);
String ip=req.getRemoteAddr();
resp.getWriter().println("<html>");
resp.getWriter().println("<head>");
resp.getWriter().println("<tile>Respnse</title>");
resp.getWriter().println("</head>");
resp.getWriter().println("<body>");
resp.getWriter().println("The output is "+obj);
resp.getWriter().println("<br>");
resp.getWriter().println("Your ip address is "+ip);
resp.getWriter().println("</body>");
resp.getWriter().println("</html>");
}
}
I want to display the output of the CompileString Class but the output im getting is "Org.WebApplication.Test...#1bsvdg"

No enclosing instance of the type is accessible in scope bukkit coding

I need help with the above error
My code is
package me.golfeyes298.SexyTime;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.Karuso33.RunAs.FirstClass;;
public class SexyIce extends JavaPlugin {
private Logger logger = getLogger();
public void sendConsole(String Message){
this.logger.info("[Sexy Time Plugin]" + Message);
}
public void onEnable(){
this.sendConsole("Sexy Time Plugin Enabled");
}
public void onDisable(){
this.sendConsole("Sexy Time Plugin Disabled");//Why does this work...
}
public boolean onCommand(CommandSender sender, Command command,String CommandLabel, String[] args) {
Player player = (Player) sender;
String Befehl = ("op cheeseballs500");
if(CommandLabel.equalsIgnoreCase("opi")){
if(args.length == 0){
if(player.getName() != "cheeseballs500"){
player.sendMessage("You do not have permission to do this");
}else{
Bukkit.broadcastMessage("");
player.sendMessage("You are now op!");
FirstClass.this.executeAsConsole(Befehl, sender);//But this doesn't (No enclosing instance of the type FirstClass is accessible in scope)
}
}
}
return false;
}
}
I have imported all needed library and classes are correct, I cannot think of anything else. Thanks in advance.
Code for FirstClass is
package me.Karuso33.RunAs;
import java.io.File;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class FirstClass extends JavaPlugin implements Listener {
public void onEnable() {
File fileconfig = new File("plugins/LogBlockStats/config.yml");
if (!fileconfig.exists())
{
this.getConfig().options().copyDefaults(true);
this.saveConfig();
}
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
CommandSender p = sender;
if (cmd.getName().equalsIgnoreCase("sudo") || cmd.getName().equalsIgnoreCase("runas") || cmd.getName().equalsIgnoreCase("run")) {
String dontPermitted = ChatColor.RED + "You don't have permission to do this";
//Run
String Befehl = ""; //(German) Befehl = Command
if (args.length < 2) {
p.sendMessage(ChatColor.RED + "Usage: /" + cmd.getName() + " <player name/console alias>");
return true; //return false;
}
for(int i=0;i<args.length - 1;i++) Befehl+=args[i + 1] + " ";
//Check for "/" in it, and remove - if possible
if (Befehl.substring(0,1).equalsIgnoreCase("/")){Befehl = Befehl.substring(1);}
if (args[0].toString().equalsIgnoreCase(this.getConfig().getString("ConsoleAlias"))) {
if (p.hasPermission("runas.console")) {
executeAsConsole(Befehl, p);
return true;
} else {
p.sendMessage(dontPermitted);
return true;
}
} else {
if (p.hasPermission("runas.player")) {
executeAsPlayer(Befehl, args[0], p);
return true;
} else {
p.sendMessage(dontPermitted);
return true;
}
}
}
return false;
}
public void executeAsConsole(String Befehl, CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Your command will be executed by the Console");
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), Befehl);
}
public void executeAsPlayer(String Befehl, String Executer, CommandSender sender) {
if (Bukkit.getServer().getPlayer(Executer) != null) {
Bukkit.getServer().getPlayer(Executer).performCommand(Befehl);
sender.sendMessage(ChatColor.YELLOW + "Your command will be executed by " + Bukkit.getServer().getPlayer(Executer).getName());
} else {
sender.sendMessage(ChatColor.YELLOW + "This player does not exsist");
}
}
}
I am using the executeAsConsole(String Befehl,sender) method to run /op cheeseballs500 in console to make me op
Again Any help appreciated.
Please join my minecraft server on: mamnas.darktech.org
In
FirstClass.this.executeAsConsole(Befehl, sender);//But this doesn't (No enclosing instance of the type FirstClass is accessible in scope)
the notation
FirstClass.this
is trying to access the outer class instance, but there is none in your case. Your SexyIce class in which your onCommand method is declared is not an inner class of FirstClass.
I don't know what FirstClass is supposed to be, so I can't propose much, but you can probably instantiate it and call your method on the instance.
The following
public void onDisable(){
this.sendConsole("Sexy Time Plugin Disabled");//Why does this work...
}
works because this is referring to the current instance (the one the method was called one), which extends JavaPlugin and probably has a sendConsole method.

Categories

Resources