• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <errno.h>
22 
23 #include "device.h"
24 #include "screen_ui.h"
25 
26 class Nanohub_Device : public Device
27 {
28 public:
Nanohub_Device(ScreenRecoveryUI * ui)29     Nanohub_Device(ScreenRecoveryUI* ui) : Device(ui) {}
30     bool PostWipeData();
31 };
32 
PostWipeData()33 bool Nanohub_Device::PostWipeData()
34 {
35     int fd;
36 
37     fd = open("/sys/class/nanohub/nanohub/erase_shared", O_WRONLY);
38     if (fd < 0) {
39         printf("error: open erase_shared failed: %s\n", strerror(errno));
40     } else {
41         if (write(fd, "1\n", 2) != 2) {
42             printf("error: write to erase_shared failed: %s\n", strerror(errno));
43         } else {
44             printf("Successfully erased nanoapps.\n");
45         }
46         close(fd);
47     }
48 
49     // open/write failure caused by permissions issues would persist across
50     // reboots, so always return true to prevent a factory reset failure loop.
51     return true;
52 }
53 
make_device()54 Device *make_device()
55 {
56     return new Nanohub_Device(new ScreenRecoveryUI);
57 }
58